Class: Problem::FSP
- Inherits:
-
Object
- Object
- Problem::FSP
- Defined in:
- lib/opt_alg_framework/problem/fsp.rb
Overview
FSP class have a inner class Schedule
Defined Under Namespace
Classes: Schedule
Constant Summary collapse
- @@bigger =
Used in makespan function to compare two execution times (also if one of them or the two are blank)
Proc.new do |a, b| a ||= b ||= 0 if a > b ||= 0 then a else b end end
Instance Attribute Summary collapse
-
#default_solution ⇒ Object
readonly
Is the sequence of tasks ordered from 0…N.
Instance Method Summary collapse
-
#initialize ⇒ FSP
constructor
Initialize the FSP problem with a empty schedule.
-
#load_schedule(path, transpose = false) ⇒ Object
Load the production schedule from a file.
-
#makespan(options = {}, block = @@bigger) ⇒ Object
(also: #fitness)
Fitness function.
Constructor Details
Instance Attribute Details
#default_solution ⇒ Object (readonly)
Is the sequence of tasks ordered from 0…N
31 32 33 |
# File 'lib/opt_alg_framework/problem/fsp.rb', line 31 def default_solution @default_solution end |
Instance Method Details
#load_schedule(path, transpose = false) ⇒ Object
Load the production schedule from a file
45 46 47 48 |
# File 'lib/opt_alg_framework/problem/fsp.rb', line 45 def load_schedule(path, transpose = false) @schedule.build_from_file(path, transpose) @default_solution = (0...@schedule.schedule.row_size).to_a end |
#makespan(options = {}, block = @@bigger) ⇒ Object Also known as: fitness
Fitness function. The hash options are:
-
schedule: matrix of the production schedule;
-
task: task index;
-
machine: machine index;
-
memory: store the total time spent at the point where the task index X is processed at the machine index Y (that avoid desnecessary recursive calls);
-
tasks_sequence: sequence of tasks used to reorganize the schedule after calculate its makespan.
The default use of the method is: inform the tasks sequence as parameter and the method do all the work, returning the makespan as result.
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 |
# File 'lib/opt_alg_framework/problem/fsp.rb', line 59 def makespan( = {}, block = @@bigger) if [:tasks_sequence] schedule = @schedule.reorder_schedule([:tasks_sequence]) makespan({schedule: schedule, task: schedule.row_size - 1, machine: schedule.column_size - 1, memory: {}}, block) else schedule = [:schedule] task = [:task] machine = [:machine] memory = [:memory] key = "#{task},#{machine}" time = schedule[task, machine] if task == 0 && machine == 0 return time end if task > 0 # Before everithing, calculate the time spent in the tasks from N to 0 time_task_before = memory["#{task - 1},#{machine}"] time_task_before = makespan({schedule: schedule, task: task - 1, machine: machine, memory: memory}, block) if memory["#{task - 1},#{machine}"].nil? end if machine > 0 # Calculate the time spent at the machines from N to 0 time_machine_before = memory["#{task},#{machine - 1}"] time_machine_before = makespan({schedule: schedule, task: task, machine: machine - 1, memory: memory}, block) if memory["#{task},#{machine - 1}"].nil? end total_time = block.call(time_task_before, time_machine_before) + time # Calculate the total time memory[key] = total_time # Store the total time total_time end end |