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 pathmain-example.rb
53 lines (45 loc) · 1.64 KB
/
main-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
require 'rubygems'
require 'main'
require 'lib/timetabling'
Main {
keyword('severity'){
cast :int
description 'Severity of the timetabling problem'
default 4
validate {|i| i >= 4 && i <= 8}
}
keyword('mutation'){
description 'Mutation used in the evolutionary algorithm, see lib/mutations.rb'
default "DumbSwappingMutation"
validate {|mutation| Kernel.const_get(mutation)}
}
keyword('recombination'){
description 'Recombination used in the evolutionary algorithm, see lib/recombinations.rb'
default "IdentityRecombination"
validate {|recombination| Kernel.const_get(recombination)}
}
keyword('iterations'){
cast :int
description 'Algorihm will stop after given iterations or run indefinitely if 0'
default 5_000_000
validate {|i| i >= 0}
}
keyword('time limit'){
cast :int
description 'Algorihm will stop after given time limit or run indefinitely if 0'
default 0.0
validate {|i| i >= 0.0}
}
keyword('cycles'){
cast :int
description 'Number of times the algorithm will run'
default 1
validate {|i| i >= 1}
}
def run
constraints = Timetabling::read_timetable_data(params['severity'].value)
params["cycles"].value.times do
Timetabling::run(:constraints => constraints, :mutation => Kernel.const_get(params["mutation"].value).new, :recombination => Kernel.const_get(params["recombination"].value).new, :number_of_slots => 30, :population_size => 1, :childs => 1, :recombination_chance => 0.0, :mutation_chance => 1.0, :iteration_limit => params["iterations"].value, :time_limit => params["time limit"].value)
end
end
}