== LoadBalancingMain.java == {{{~cpp /** * @author Administrator * * To change this generated comment edit the template variable "typecomment": * Window>Preferences>Java>Templates. * To enable and disable the creation of type comments go to * Window>Preferences>Java>Code Generation. */ import junit.framework.*; import junit.textui.*; public class LoadBalancingMain { public static void main(String[] args) { TestSuite suite = new TestSuite(); suite.addTestSuite(TestLoadBalancing.class); TestRunner.run(suite); } } }}} == TestLoadBalancing.java == {{{~cpp /** * @author Administrator * * To change this generated comment edit the template variable "typecomment": * Window>Preferences>Java>Templates. * To enable and disable the creation of type comments go to * Window>Preferences>Java>Code Generation. */ import junit.framework.*; public class TestLoadBalancing extends TestCase{ public void testSetNGetData() { LoadBalancing bal = new LoadBalancing(3); int sData[] = {1,3,3}; int gData[]; bal.setData(sData); gData = bal.getData(); for(int i=0; iPreferences>Java>Templates. * To enable and disable the creation of type comments go to * Window>Preferences>Java>Code Generation. */ public class LoadBalancing { private int _processor[]; private int _processorNum; private int _movedJob; public LoadBalancing(int processorNum) { _processor = new int[processorNum]; _processorNum = processorNum; } public int getProcessorNum() { return _processorNum; } public int[] getProcessorInfo() { return _processor; } public int getSumOfJob() { int sum=0; for(int i=0; i<_processor.length; i++) sum+=_processor[i]; return sum; } public void setData(int[] data) { for(int i=0; i_processor[i])?_processor[i]:ret; } return ret; } public boolean checkLeft(int index) { int average = getSumOfJob() / _processor.length; int remian = getSumOfJob() % _processor.length; int leftSum = 0; int rightSum = 0; int partialLength = (index==0)? 1:index; if( index==0 ) { return false; } // 왼쪽 평균<오른쪽 평균 for(int i=0; i leftSum/index ) { return true; }*/ else { return false; } } public boolean checkRight(int index) { int average = getSumOfJob() / _processor.length; int remian = getSumOfJob() % _processor.length; int leftSum = 0; int rightSum = 0; int partialLength = (index==0)? 1:index; if( index==_processor.length-1 ) { return false; } // 왼쪽 평균>오른쪽 평균 for(int i=0; i<=index; i++) { leftSum+=_processor[i]; } if(index==0) leftSum = _processor[0]; rightSum = getSumOfJob() - leftSum; /*if( average != 0 ) { System.out.println("인덱스 : " + index ); System.out.println("평균 : " + _processor[index] + "왼쪽나머지:" + (leftSum%average) + "오른쪽 나머지 : " + (rightSum%average) ); }*/ if( average==0 ) { if( rightSum< (_processor.length-index-1) ) return true; else return false; } else if( leftSum/(index+1) > rightSum/(_processor.length-index-1) ){ return true; } else if( leftSum/(index+1) == rightSum/(_processor.length-index-1 ) && _processor[index] > rightSum/(_processor.length-index-1) ) { System.out.println("라이트"); return true; } else { return false; } } public void printInfo() { System.out.println(); System.out.println("옮긴 횟수: " + getMovedJob() ); for(int i=0; i<_processor.length; i++) { System.out.print(_processor[i] + " " ); } System.out.println(); } public int getMovedJob() { return _movedJob; } } }}} ---- LoadBalancingProblem