Class: Symian::Configuration

Inherits:
Object
  • Object
show all
Includes:
Configurable
Defined in:
lib/symian/configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Configuration

Returns a new instance of Configuration.



24
25
26
# File 'lib/symian/configuration.rb', line 24

def initialize(filename)
  @filename = filename
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



22
23
24
# File 'lib/symian/configuration.rb', line 22

def filename
  @filename
end

Class Method Details

.load_from_file(filename) ⇒ Object

Raises:

  • (ArgumentError)


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/symian/configuration.rb', line 79

def self.load_from_file(filename)
  # allow filename, string, and IO objects as input
  raise ArgumentError, "File #{filename} does not exist!" unless File.exists?(filename)

  # create configuration object
  conf = Configuration.new(filename)

  # take the file content and pass it to instance_eval
  conf.instance_eval(File.new(filename, 'r').read)

  # validate and finalize configuration
  conf.validate

  # return new object
  conf
end

Instance Method Details

#end_timeObject



28
29
30
# File 'lib/symian/configuration.rb', line 28

def end_time
  @start_time + @duration
end

#reallocate_ops_and_clone(operators) ⇒ Object



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
# File 'lib/symian/configuration.rb', line 51

def reallocate_ops_and_clone(operators)
  raise 'Wrong allocation' unless operators.size == @support_groups.size

  new_conf = Configuration.new(@filename)
  new_conf.start_time          @start_time
  new_conf.duration            @duration
  new_conf.warmup_duration     @warmup_duration
  new_conf.incident_generation @incident_generation
  new_conf.transition_matrix   @transition_matrix
  new_conf.cost_analysis       @cost_analysis

  new_sgs = {}
  @support_groups.zip(operators) do |(sg_name,sg_conf),num_ops|
    new_sgs[sg_name] = {
      work_time: sg_conf[:work_time], # this is already frozen
      operators: {
        number: num_ops,
        workshift: sg_conf[:operators][:workshift], # this is already frozen
      },
    }
  end
  new_sgs.deep_freeze

  new_conf.support_groups(new_sgs)

  new_conf
end

#validateObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/symian/configuration.rb', line 32

def validate
  # @start_time      = @start_time.to_i
  # @duration        = @duration.to_i
  # @warmup_duration = @warmup_duration.to_i

  if @incident_generation[:type] == :file
    @incident_generation[:source][:path].gsub!('<pwd>', File.expand_path(File.dirname(@filename)))
  end

  # freeze everything!
  @start_time.deep_freeze
  @duration.deep_freeze
  @warmup_duration.deep_freeze
  @incident_generation.deep_freeze
  @transition_matrix.deep_freeze
  @cost_analysis.deep_freeze
  @support_groups.deep_freeze
end