Class: OPL::LinearProgram
- Inherits:
-
Object
- Object
- OPL::LinearProgram
- Defined in:
- lib/opl.rb
Instance Attribute Summary collapse
-
#column_bounds ⇒ Object
Returns the value of attribute column_bounds.
-
#constraints ⇒ Object
Returns the value of attribute constraints.
-
#data ⇒ Object
Returns the value of attribute data.
-
#data_hash ⇒ Object
Returns the value of attribute data_hash.
-
#epsilon ⇒ Object
Returns the value of attribute epsilon.
-
#error_message ⇒ Object
Returns the value of attribute error_message.
-
#matrix ⇒ Object
Returns the value of attribute matrix.
-
#matrix_solution ⇒ Object
Returns the value of attribute matrix_solution.
-
#mip_message ⇒ Object
Returns the value of attribute mip_message.
-
#objective ⇒ Object
Returns the value of attribute objective.
-
#original_constraints ⇒ Object
Returns the value of attribute original_constraints.
-
#rglpk_object ⇒ Object
Returns the value of attribute rglpk_object.
-
#rows ⇒ Object
Returns the value of attribute rows.
-
#simplex_message ⇒ Object
Returns the value of attribute simplex_message.
-
#solution ⇒ Object
Returns the value of attribute solution.
-
#solution_type ⇒ Object
Returns the value of attribute solution_type.
-
#solver ⇒ Object
Returns the value of attribute solver.
-
#stop_processing ⇒ Object
Returns the value of attribute stop_processing.
-
#variable_types ⇒ Object
Returns the value of attribute variable_types.
Instance Method Summary collapse
-
#initialize ⇒ LinearProgram
constructor
A new instance of LinearProgram.
- #keys ⇒ Object
- #solution_as_matrix ⇒ Object
Constructor Details
#initialize ⇒ LinearProgram
Returns a new instance of LinearProgram.
758 759 760 761 762 763 764 |
# File 'lib/opl.rb', line 758 def initialize @rows = [] @data = [] @epsilon = $default_epsilon @matrix_solution = {} @stop_processing = false end |
Instance Attribute Details
#column_bounds ⇒ Object
Returns the value of attribute column_bounds.
747 748 749 |
# File 'lib/opl.rb', line 747 def column_bounds @column_bounds end |
#constraints ⇒ Object
Returns the value of attribute constraints.
735 736 737 |
# File 'lib/opl.rb', line 735 def constraints @constraints end |
#data ⇒ Object
Returns the value of attribute data.
744 745 746 |
# File 'lib/opl.rb', line 744 def data @data end |
#data_hash ⇒ Object
Returns the value of attribute data_hash.
745 746 747 |
# File 'lib/opl.rb', line 745 def data_hash @data_hash end |
#epsilon ⇒ Object
Returns the value of attribute epsilon.
748 749 750 |
# File 'lib/opl.rb', line 748 def epsilon @epsilon end |
#error_message ⇒ Object
Returns the value of attribute error_message.
750 751 752 |
# File 'lib/opl.rb', line 750 def end |
#matrix ⇒ Object
Returns the value of attribute matrix.
741 742 743 |
# File 'lib/opl.rb', line 741 def matrix @matrix end |
#matrix_solution ⇒ Object
Returns the value of attribute matrix_solution.
749 750 751 |
# File 'lib/opl.rb', line 749 def matrix_solution @matrix_solution end |
#mip_message ⇒ Object
Returns the value of attribute mip_message.
743 744 745 |
# File 'lib/opl.rb', line 743 def end |
#objective ⇒ Object
Returns the value of attribute objective.
734 735 736 |
# File 'lib/opl.rb', line 734 def objective @objective end |
#original_constraints ⇒ Object
Returns the value of attribute original_constraints.
736 737 738 |
# File 'lib/opl.rb', line 736 def original_constraints @original_constraints end |
#rglpk_object ⇒ Object
Returns the value of attribute rglpk_object.
739 740 741 |
# File 'lib/opl.rb', line 739 def rglpk_object @rglpk_object end |
#rows ⇒ Object
Returns the value of attribute rows.
737 738 739 |
# File 'lib/opl.rb', line 737 def rows @rows end |
#simplex_message ⇒ Object
Returns the value of attribute simplex_message.
742 743 744 |
# File 'lib/opl.rb', line 742 def end |
#solution ⇒ Object
Returns the value of attribute solution.
738 739 740 |
# File 'lib/opl.rb', line 738 def solution @solution end |
#solution_type ⇒ Object
Returns the value of attribute solution_type.
752 753 754 |
# File 'lib/opl.rb', line 752 def solution_type @solution_type end |
#solver ⇒ Object
Returns the value of attribute solver.
740 741 742 |
# File 'lib/opl.rb', line 740 def solver @solver end |
#stop_processing ⇒ Object
Returns the value of attribute stop_processing.
751 752 753 |
# File 'lib/opl.rb', line 751 def stop_processing @stop_processing end |
#variable_types ⇒ Object
Returns the value of attribute variable_types.
746 747 748 |
# File 'lib/opl.rb', line 746 def variable_types @variable_types end |
Instance Method Details
#keys ⇒ Object
754 755 756 |
# File 'lib/opl.rb', line 754 def keys [:objective, :constraints, :rows, :solution, :formatted_constraints, :rglpk_object, :solver, :matrix, :simplex_message, :mip_message, :data] end |
#solution_as_matrix ⇒ Object
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 |
# File 'lib/opl.rb', line 766 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 |