2017-05-12 1 views
0

안녕하세요, M/M/1 대기열 차단 시간을 시뮬레이트했습니다.이 매우 해결책이 떠오르지 만 불행히도 객체 지향적이지 않습니다. 문제는 M/M/2 시스템에서 시뮬레이션하고 싶다는 것입니다. , 예를 들어 나는 19와 mu를 20으로 초기화했다. 계산을 쉽게하기 위해 힌트와 코드 예제를 크게 높이 평가할 것이다.M/M/2 시스템에서 java에서 시뮬레이트 된 큐의 차단 시간을 처리하는 방법은 무엇입니까?

public class Main { 
    public static void main(String[] args) { 
     final int MAX_ENTITY = 100000; 
     final int SYSTEM_CAPACITY = 5; 
     final int BUSY = 1; 
     final int IDLE = 0; 
     double lambda = 19, mu = 20; 
     int blocked = 0; 
     int queue_length = 0; 
     int server_state = IDLE; 
     int entity = 0; 
     double next_av = getArivalRand(lambda); 
     double next_dp = next_av + getDeparturedRand(lambda); 
     while (entity <= MAX_ENTITY) { 
      //Arrival 
      if (next_av <= next_dp) { 
       entity++; 
       if (server_state == IDLE) { 
        server_state = BUSY; 
       } else if (queue_length < SYSTEM_CAPACITY - 1) { 
        queue_length++; 
       } else { 
        blocked++; 
       } 
       next_av += getArivalRand(lambda); 
      } // Departure 
      else if (queue_length > 0) { 
       queue_length--; 
       next_dp = next_dp + getDeparturedRand(mu); 
      } else { 
       server_state = IDLE; 
       next_dp = next_av + getDeparturedRand(mu); 
      } 
     } 
     System.out.println("Blocked Etity:" + blocked + "\n"); 
    } 

    public static double getArivalRand(double lambda) { 
     return -1/lambda * Math.log(1 - Math.random()); 
    } 

    public static double getDeparturedRand(double mu) { 
     return -1/mu * Math.log(1 - Math.random()); 
    } 
} 

편집 :

체크 here u는 큐 이론

+2

공손하십시오 의로드 밸런싱을위한 요점 파일에서 예제 코드, 그것은 서버의 수가 더 많은 정보에 https 여기를 읽어냅니다 : //en.wikipedia.org/wiki/M/M/1_queue –

+0

그건 바보 같은 농담 이었어. 질문에 대한 링크를 수정해야합니다. – Michael

+0

구체적으로 귀하의 질문은 무엇입니까? 즉, 귀하의 코드는 어떻게해서는 안되며 그렇게하지 않아야합니까? – pjs

답변

0

당신이 코드가 M/M/2을 달성하기 위해 심각한 리팩토링을 필요가있어 소년 오에 대해 모르는 경우. 내가 원하는 것을 구현한다고 생각하는 here 요점 파일을 작성했습니다. 요점 파일에서 두 서버의 두 대기열을 균형 조정하기 위해 Dispatcher 클래스를 생성했으며 두 개의 시드로 시뮬레이션했습니다. 훨씬 더 객체 지향적입니다. 접근 방식은, 여기

이 작업

if (server1.getQueueLength() < server2.getQueueLength()) 
    currentServer = server1; 
else if (server1.getQueueLength() > server2.getQueueLength()) 
    currentServer = server2; 
else if (currentServer == server1) 
    currentServer = server2; 
else 
    currentServer = server1; 
+0

오, 감사합니다. 정확히 내가 원했던 것입니다. <3 –

관련 문제