The Doctor Rostering Problem - Asser Fahrenholz

The Doctor Rostering Problem - Asser Fahrenholz The Doctor Rostering Problem - Asser Fahrenholz

asser.fahrenholz.dk
from asser.fahrenholz.dk More from this publisher
27.07.2013 Views

Appendix A. Implementation 73 33 } 34 return res ; 35 } 36 return null ; 37 } 38 39 public ArrayList < ArrayList < Doctor >> choose2 ( ArrayList < Doctor > b, int k) { 40 res = new ArrayList < ArrayList < Doctor > >(); 41 42 return enumerate2 (b, b. size () , k); 43 } 44 45 private void swap2 ( ArrayList < Doctor > b, int i, int j) { 46 Doctor temp = b. get (i); 47 b. set (i, b. get (j)); 48 b. set (j, temp ); 49 } 50 51 public ArrayList < ArrayList < Doctor >> getRes () { 52 return res ; 53 } 54 } A.5.3 Day assignments 1 /* * 2 * Returns the best doctor for a given shift on a given day . 3 * 4 * @param dayInt 5 * the day 6 * @param RCLsize 7 * the size the RCL 8 * @param minimizing 9 * @return The best doctor for the shift 10 */ 11 public Change getBestChange ( 12 int dayInt , RCLParameter RCLsize , boolean minimizing , Rules rules ) { 13 14 if ( rules != null ) { 15 this . myRules = rules ; 16 } 17 18 Vector >> bestChange = new Vector > >(); 20 Permutation t = new Permutation (); 21 22 ArrayList < Doctor > doc = new ArrayList < Doctor >() ; 23 doc . addAll ( docs ); 24 25 t. choose2 (doc , this . get ( dayInt ). getAllMiddayShifts (). size ()); 26 27 ArrayList < ArrayList < Doctor >> set = t. getRes ();

Appendix A. Implementation 74 28 Change c; 29 for ( int i = 0; i < set . size (); i ++) { 30 c = new Change (); 31 ArrayList < Doctor > subsetDoctors = set . get (i); 32 HashSet < Shift > shiftset = this . get ( dayInt ). getAllMiddayShifts (); 33 ArrayList < Shift > sSet = new ArrayList < Shift >() ; 34 sSet . addAll ( shiftset ); 35 36 for ( int j = 0; j < shiftset . size (); j ++) { 37 c. put ( sSet . get (j), subsetDoctors . get (j)); 38 } 39 40 Pair < Integer , Pair < HashMap < Shift , HashSet >>, HashMap < Shift , HashSet >>>> sol = this . getSolutionValue ( false , null ); 41 int oldScore = sol . getE (); 42 int oldVio = sol . getV (). getE (). size (); 43 44 this . performChange (c, false ); 45 46 Pair < Integer , Pair < HashMap < Shift , HashSet >>, HashMap < Shift , HashSet >>>> newSol = this . getSolutionValue ( false , null ); 47 int newScore = newSol . getE (); 48 int newvio = newSol . getV (). getE (). size (); 49 50 51 double scoreInc = newScore - oldScore ; 52 int vioInc = newvio - oldVio ; 53 // Undo the change : 54 this . performChange (c, true ); 55 // Sort by best change : 56 if ( bestChange . size () == 0) { 57 bestChange . add ( new Pair < Change , Pair < Double , Integer > >(c, new Pair < Double , Integer >( scoreInc , vioInc ))); 58 } else { 59 myFor : 60 for ( int k = 0; k < bestChange . size (); k ++) { 61 Pair < Change , Pair < Double , Integer >> changeScore = bestChange . get (k); 62 if ( changeScore . getV (). getV () > vioInc ) { 63 bestChange . add ( bestChange . indexOf ( changeScore ), 64 new Pair < Change , Pair < Double , Integer > >(c, new Pair < Double , Integer >( scoreInc , vioInc ))); 65 break myFor ; 66 } 67 if ( changeScore . getV (). getV () == vioInc ) { 68 if (( changeScore . getV (). getE () < scoreInc && ! minimizing ) || ( changeScore . getV (). getE () > scoreInc && minimizing )) { 69 bestChange . add ( bestChange . indexOf ( changeScore ), 70 new Pair < Change , Pair < Double , Integer > >(c, new Pair < Double , Integer >( scoreInc , vioInc ))); 71 break myFor ; 72 } 73

Appendix A. Implementation 74<br />

28 Change c;<br />

29 for ( int i = 0; i < set . size (); i ++) {<br />

30 c = new Change ();<br />

31 ArrayList < <strong>Doctor</strong> > subset<strong>Doctor</strong>s = set . get (i);<br />

32 HashSet < Shift > shiftset = this . get ( dayInt ). getAllMiddayShifts ();<br />

33 ArrayList < Shift > sSet = new ArrayList < Shift >() ;<br />

34 sSet . addAll ( shiftset );<br />

35<br />

36 for ( int j = 0; j < shiftset . size (); j ++) {<br />

37 c. put ( sSet . get (j), subset<strong>Doctor</strong>s . get (j));<br />

38 }<br />

39<br />

40 Pair < Integer , Pair < HashMap < Shift , HashSet >>,<br />

HashMap < Shift , HashSet >>>> sol = this . getSolutionValue (<br />

false , null );<br />

41 int oldScore = sol . getE ();<br />

42 int oldVio = sol . getV (). getE (). size ();<br />

43<br />

44 this . performChange (c, false );<br />

45<br />

46 Pair < Integer , Pair < HashMap < Shift , HashSet >>,<br />

HashMap < Shift , HashSet >>>> newSol = this .<br />

getSolutionValue ( false , null );<br />

47 int newScore = newSol . getE ();<br />

48 int newvio = newSol . getV (). getE (). size ();<br />

49<br />

50<br />

51 double scoreInc = newScore - oldScore ;<br />

52 int vioInc = newvio - oldVio ;<br />

53 // Undo the change :<br />

54 this . performChange (c, true );<br />

55 // Sort by best change :<br />

56 if ( bestChange . size () == 0) {<br />

57 bestChange . add ( new Pair < Change , Pair < Double , Integer > >(c, new<br />

Pair < Double , Integer >( scoreInc , vioInc )));<br />

58 } else {<br />

59 myFor :<br />

60 for ( int k = 0; k < bestChange . size (); k ++) {<br />

61 Pair < Change , Pair < Double , Integer >> changeScore = bestChange .<br />

get (k);<br />

62 if ( changeScore . getV (). getV () > vioInc ) {<br />

63 bestChange . add ( bestChange . indexOf ( changeScore ),<br />

64 new Pair < Change , Pair < Double , Integer > >(c, new<br />

Pair < Double , Integer >( scoreInc , vioInc )));<br />

65 break myFor ;<br />

66 }<br />

67 if ( changeScore . getV (). getV () == vioInc ) {<br />

68 if (( changeScore . getV (). getE () < scoreInc && ! minimizing )<br />

|| ( changeScore . getV (). getE () > scoreInc && minimizing )) {<br />

69 bestChange . add ( bestChange . indexOf ( changeScore ),<br />

70 new Pair < Change , Pair < Double , Integer > >(c,<br />

new Pair < Double , Integer >( scoreInc , vioInc )));<br />

71 break myFor ;<br />

72 }<br />

73

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!