~kaaloo/workplan/trunk

« back to all changes in this revision

Viewing changes to src/groovy/com/pilango/workplan/ChocoHelper.groovy

  • Committer: Luis Arias
  • Date: 2008-07-04 17:04:59 UTC
  • Revision ID: luis.arias@pilango.com-20080704170459-kxot2xwg9dodsjpu
Started work on shift scheduling for a complete workforce.  Renamed ConstraintHelper to ChocoHelper which will become a utility to help add different types of contraints to the model.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 
15
15
import static choco.Choco.*
16
16
 
17
 
class ConstraintHelper {
 
17
class ChocoHelper {
18
18
        
19
19
        static TimeSlotService timeSlotService = new TimeSlotService()
20
20
        
21
21
        CPModel m
 
22
        ShiftVars [] shiftVars
22
23
    IntegerVariable [] slotIndices
23
24
    IntegerVariable [] slotDistances
24
25
        def total
25
26
        
26
 
        ConstraintHelper(CPModel m) {
 
27
        ChocoHelper(CPModel m) {
27
28
                this.m = m
28
29
        }
 
30
        
 
31
        void setup(Site [] sites, Shift [] shifts, Worker [] workers, int daysInMonth) {
 
32
        int id = 0
 
33
        int [] siteIds = sites.collect { it.id }
 
34
        int [] workerIds = workers.collect { it.id }
 
35
        shiftVars = shifts.collect {
 
36
            new ShiftVars(id++, siteIds, workerIds, daysInMonth)
 
37
        }               
 
38
        }
29
39
    
30
40
    void bestTimeSlots(TimeSlot [] emptySlots, TimeSlot [] preferredSlots) {
31
41
        int NB_SLOTS = emptySlots.size()
41
51
        m.addConstraint(allDifferent(slotIndices))
42
52
        m.addConstraint(eq(total, sum(slotDistances)))          
43
53
    }
 
54
    
 
55
    void setWorkerDaysOffConstraints(Worker [] workers) {
 
56
        workers.each { worker ->
 
57
                worker.daysOff.each { dayOff ->
 
58
                        shiftVars.each { shiftVar ->
 
59
                                m.addConstraint(not(and(eq(shiftVar.workerId, worker.id), eq(shiftVar.dayOfMonth, dayOff))))
 
60
                        }
 
61
                }
 
62
        }
 
63
    }    
44
64
}
 
 
b'\\ No newline at end of file'