Class: OPL::LinearProgram

Inherits:
Object
  • Object
show all
Defined in:
lib/opl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLinearProgram

Returns a new instance of LinearProgram.



772
773
774
775
776
777
778
# File 'lib/opl.rb', line 772

def initialize
	@rows = []
	@data = []
	@epsilon = $default_epsilon
	@matrix_solution = {}
	@stop_processing = false
end

Instance Attribute Details

#column_boundsObject

Returns the value of attribute column_bounds.



762
763
764
# File 'lib/opl.rb', line 762

def column_bounds
  @column_bounds
end

#constraintsObject

Returns the value of attribute constraints.



750
751
752
# File 'lib/opl.rb', line 750

def constraints
  @constraints
end

#dataObject

Returns the value of attribute data.



759
760
761
# File 'lib/opl.rb', line 759

def data
  @data
end

#data_hashObject

Returns the value of attribute data_hash.



760
761
762
# File 'lib/opl.rb', line 760

def data_hash
  @data_hash
end

#epsilonObject

Returns the value of attribute epsilon.



763
764
765
# File 'lib/opl.rb', line 763

def epsilon
  @epsilon
end

#error_messageObject

Returns the value of attribute error_message.



765
766
767
# File 'lib/opl.rb', line 765

def error_message
  @error_message
end

#matrixObject

Returns the value of attribute matrix.



756
757
758
# File 'lib/opl.rb', line 756

def matrix
  @matrix
end

#matrix_solutionObject

Returns the value of attribute matrix_solution.



764
765
766
# File 'lib/opl.rb', line 764

def matrix_solution
  @matrix_solution
end

#mip_messageObject

Returns the value of attribute mip_message.



758
759
760
# File 'lib/opl.rb', line 758

def mip_message
  @mip_message
end

#objectiveObject

Returns the value of attribute objective.



749
750
751
# File 'lib/opl.rb', line 749

def objective
  @objective
end

#original_constraintsObject

Returns the value of attribute original_constraints.



751
752
753
# File 'lib/opl.rb', line 751

def original_constraints
  @original_constraints
end

#rglpk_objectObject

Returns the value of attribute rglpk_object.



754
755
756
# File 'lib/opl.rb', line 754

def rglpk_object
  @rglpk_object
end

#rowsObject

Returns the value of attribute rows.



752
753
754
# File 'lib/opl.rb', line 752

def rows
  @rows
end

#simplex_messageObject

Returns the value of attribute simplex_message.



757
758
759
# File 'lib/opl.rb', line 757

def simplex_message
  @simplex_message
end

#solutionObject

Returns the value of attribute solution.



753
754
755
# File 'lib/opl.rb', line 753

def solution
  @solution
end

#solverObject

Returns the value of attribute solver.



755
756
757
# File 'lib/opl.rb', line 755

def solver
  @solver
end

#stop_processingObject

Returns the value of attribute stop_processing.



766
767
768
# File 'lib/opl.rb', line 766

def stop_processing
  @stop_processing
end

#variable_typesObject

Returns the value of attribute variable_types.



761
762
763
# File 'lib/opl.rb', line 761

def variable_types
  @variable_types
end

Instance Method Details

#keysObject



768
769
770
# File 'lib/opl.rb', line 768

def keys
	[:objective, :constraints, :rows, :solution, :formatted_constraints, :rglpk_object, :solver, :matrix, :simplex_message, :mip_message, :data]
end

#solution_as_matrixObject



780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
# File 'lib/opl.rb', line 780

def solution_as_matrix
	lp = self
	variables = lp.solution.keys.map do |key|
		key.scan(/[a-z]/)[0] if key.include?("[")
	end.uniq.find_all{|e|!e.nil?}
	matrix_solution = {}
	variables.each do |var|
		elements = lp.solution.keys.find_all{|key|key.include?(var) && key.include?("[")}
		num_dims = elements[0].scan(/\]\[/).size + 1
		dim_limits = []
		indices_value_pairs = []
		[*(0..(num_dims-1))].each do |i|
			dim_limit = 0
			elements.each do |e|
				indices = e.scan(/\[\d+\]/).map{|str|str.scan(/\d+/)[0].to_i}
				value = lp.solution[e]
				indices_value_pairs << [indices, value]
				dim_limit = indices[i] if indices[i] > dim_limit
			end
			dim_limits << dim_limit+1
		end
		matrix = [].matrix(dim_limits)
		indices_value_pairs.each do |ivp|
			matrix.insert_at(ivp[0], ivp[1].to_f)
		end
		matrix_solution[var] = matrix
	end
	return(matrix_solution)
end