class Problem::FSP

require 'opt_alg_framework/problem/problem_interface'

FSP class have a inner class Schedule

Attributes

default_solution[R]

Public Class Methods

new() click to toggle source

Initialize the FSP problem with a empty schedule

# File lib/opt_alg_framework/problem/fsp.rb, line 35
def initialize
  @production = Production.new
end

Public Instance Methods

fitness(solution) click to toggle source
# File lib/opt_alg_framework/problem/fsp.rb, line 46
def fitness(solution)
  schedule = @production.reorder_schedule(solution)
  makespan(schedule: schedule, task: schedule.row_size - 1,
            machine: schedule.column_size - 1, memory: {})
end
load_instance(path) { |: false| ... } click to toggle source

Load the production schedule from a file

# File lib/opt_alg_framework/problem/fsp.rb, line 40
def load_instance(path)
  transpose = block_given? ? yield : false
  @production.build_from_file(path, transpose)
  @default_solution = (0...@production.schedule.row_size).to_a
end

Private Instance Methods

bigger(num1 = 0, num2 = 0) click to toggle source
# File lib/opt_alg_framework/problem/fsp.rb, line 54
def bigger(num1 = 0, num2 = 0)
  num1 ||= num2 ||= 0
  if num1 > num2 ||= 0 then num1 else num2 end
end
makespan(options = {}) click to toggle source

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).

# File lib/opt_alg_framework/problem/fsp.rb, line 65
def makespan(options = {})
  schedule = options[:schedule]
  task = options[:task]
  machine = options[:machine]
  memory = options[:memory]
  key = "#{task},#{machine}"
  time = schedule[task, machine]

  return time if task == 0 && machine == 0

  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) if memory["#{task - 1},#{machine}"].nil?
  end

  if machine > 0 # Calculate the time spent of the same task 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) if memory["#{task},#{machine - 1}"].nil?
  end

  total_time = bigger(time_task_before, time_machine_before) + time # Calculate the total time
  memory[key] = total_time # Store the total time
  total_time
end