This repository has been archived by the owner on Dec 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchoice-example.rb
87 lines (74 loc) · 2.27 KB
/
choice-example.rb
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
require 'rubygems'
require 'choice'
require 'lib/timetabling'
PROGRAM_VERSION = 2.1
Choice.options do
header ''
header 'Specific options:'
option :severity do
short '-s'
long '--severity=4'
desc 'Severity of the hard timetabling problem, must be an integer in {4, 5, 6, 7, 8}'
default '4'
cast Integer
valid %w(4 5 6 7 8)
end
option :mutation do
short '-m'
long '--mutation=DumbSwappingMutation'
desc 'The mutation used in the evolutionary algorithm, see lib/mutations.rb for choices'
default Kernel.const_get('TripleSwapperWithTwoCollidingConstraintsMutation')
filter do |mutation|
Kernel.const_get(mutation)
end
end
option :recombination do
short '-r'
long '--recombination=IdentityRecombination'
desc 'The recombination used in the evolutionary algorithm, see lib/recombinations.rb for choices'
default Kernel.const_get('IdentityRecombination')
filter do |recombination|
Kernel.const_get(recombination)
end
end
option :iterations do
short '-i'
long '--iterations=5_000_000'
desc 'Algorithm will stop after the allowed iterations were exceded'
default 5_000_000
cast Integer
end
option :time_limit do
short '-t'
long '--time-limit=0'
desc 'Algorithm will stop after allowed time, will run indefinitely if time limit is 0'
default 0
cast Integer
end
option :cycles do
short '-c'
long '--cycles=100'
desc 'Determines how often the algorithm will run'
default 1
cast Integer
end
separator ''
separator 'Common options: '
option :help do
long '--help'
desc 'Show this message'
end
option :version do
short '-v'
long '--version'
desc 'Show version'
action do
puts "timetabling v#{PROGRAM_VERSION}"
exit
end
end
end
constraints = Timetabling::read_timetable_data(Choice.choices[:severity])
Choice.choices[:cycles].times do
Timetabling::run(:constraints => constraints, :mutation => Choice.choices[:mutation].new, :recombination => Choice.choices[:recombination].new, :number_of_slots => 30, :population_size => 1, :childs => 1, :recombination_chance => 0.0, :mutation_chance => 1.0, :iteration_limit => Choice.choices[:iterations], :time_limit => Choice.choices[:time_limit])
end