-
Notifications
You must be signed in to change notification settings - Fork 0
/
plan.go
91 lines (81 loc) · 2.1 KB
/
plan.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package generateplan
import (
"math/rand"
"github.com/obcode/plexams.go/graph/model"
"github.com/rs/zerolog/log"
)
type Exam struct {
examGroup *model.ExamGroup
day int
slot int
}
func newExam(examGroup *model.ExamGroup) *Exam {
return &Exam{examGroup: examGroup}
}
func (exam *Exam) randomSlot() {
possibleSlots := exam.examGroup.ExamGroupInfo.PossibleSlots
slot := possibleSlots[rand.Intn(len(possibleSlots))]
exam.day = slot.DayNumber
exam.slot = slot.SlotNumber
}
type Plan struct {
exams []*Exam
fitness float64
}
func (plan *Plan) randomPlan() {
for _, exam := range plan.exams {
exam.randomSlot()
}
}
func (plan *Plan) validate() bool {
examsMap := make(map[int]*Exam)
for _, exam := range plan.exams {
examsMap[exam.examGroup.ExamGroupCode] = exam
}
for _, exam1 := range plan.exams {
if exam1.examGroup.ExamGroupInfo.NotPlannedByMe {
continue
}
for _, conflict := range exam1.examGroup.ExamGroupInfo.Conflicts {
exam2, ok := examsMap[conflict.ExamGroupCode]
if ok {
if exam2.examGroup.ExamGroupInfo.NotPlannedByMe {
if exam1.examGroup.ExamGroupCode != exam2.examGroup.ExamGroupCode {
if exam1.day == exam2.day {
if exam1.slot-exam2.slot == 1 || exam1.slot == exam2.slot {
log.Debug().
Int("exam group 1", exam1.examGroup.ExamGroupCode).Int("day1", exam1.day).Int("slot1", exam1.slot).
Int("exam group 2", exam2.examGroup.ExamGroupCode).Int("day2", exam2.day).Int("slot2", exam2.slot).
Msg("plan is not valid")
return false
}
}
}
}
}
}
}
return true
}
// func (algorithm *Algorithm) moveSlotsToFront(plan *Plan) *Plan {
// planfitness := plan.fitness
// for _, exam := range plan.exams {
// day := exam.day
// slot := exam.slot
// for i := 1; i < day; i++ {
// exam.day = i
// for j := 1; j < slot; j++ {
// exam.slot = j
// if algorithm.evaluatePlan(plan) >= planfitness {
// day = i
// slot = j
// planfitness = plan.fitness
// }
// }
// }
// exam.slot = slot
// exam.day = day
// plan.fitness = planfitness
// }
// return plan
// }