Module: Highs::Methods

Included in:
Highs
Defined in:
lib/highs/methods.rb

Instance Method Summary collapse

Instance Method Details

#lp(sense:, offset: 0, col_cost:, col_lower:, col_upper:, row_lower:, row_upper:, a_format:, a_start:, a_index:, a_value:) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/highs/methods.rb', line 3

def lp(sense:, offset: 0, col_cost:, col_lower:, col_upper:, row_lower:, row_upper:, a_format:, a_start:, a_index:, a_value:)
  num_col = col_cost.size
  num_row = row_lower.size
  num_nz = a_index.size
  a_format = FFI::MATRIX_FORMAT.fetch(a_format)
  sense = FFI::OBJ_SENSE.fetch(sense)

  model = Model.new
  check_status FFI.Highs_passLp(
    model, num_col, num_row, num_nz, a_format, sense, offset,
    DoubleArray.new(num_col, col_cost), DoubleArray.new(num_col, col_lower), DoubleArray.new(num_col, col_upper),
    DoubleArray.new(num_row, row_lower), DoubleArray.new(num_row, row_upper),
    IntArray.new(a_start.size, a_start), IntArray.new(num_nz, a_index), DoubleArray.new(num_nz, a_value),
  )
  model
end

#lp_call(**options) ⇒ Object



20
21
22
# File 'lib/highs/methods.rb', line 20

def lp_call(**options)
  lp(**options).solve
end

#mip(sense:, offset: 0, col_cost:, col_lower:, col_upper:, row_lower:, row_upper:, a_format:, a_start:, a_index:, a_value:, integrality:) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/highs/methods.rb', line 24

def mip(sense:, offset: 0, col_cost:, col_lower:, col_upper:, row_lower:, row_upper:, a_format:, a_start:, a_index:, a_value:, integrality:)
  num_col = col_cost.size
  num_row = row_lower.size
  num_nz = a_index.size
  a_format = FFI::MATRIX_FORMAT.fetch(a_format)
  sense = FFI::OBJ_SENSE.fetch(sense)
  integrality = integrality.map { |v| FFI::VAR_TYPE[v] || v }

  model = Model.new
  check_status FFI.Highs_passMip(
    model, num_col, num_row, num_nz, a_format, sense, offset,
    DoubleArray.new(num_col, col_cost), DoubleArray.new(num_col, col_lower), DoubleArray.new(num_col, col_upper),
    DoubleArray.new(num_row, row_lower), DoubleArray.new(num_row, row_upper),
    IntArray.new(a_start.size, a_start), IntArray.new(num_nz, a_index), DoubleArray.new(num_nz, a_value),
    IntArray.new(num_col, integrality)
  )
  model
end

#mip_call(**options) ⇒ Object



43
44
45
# File 'lib/highs/methods.rb', line 43

def mip_call(**options)
  mip(**options).solve.slice(:status, :obj_value, :col_value, :row_value)
end

#qp(sense:, offset: 0, col_cost:, col_lower:, col_upper:, row_lower:, row_upper:, a_format:, a_start:, a_index:, a_value:, q_format:, q_start:, q_index:, q_value:) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/highs/methods.rb', line 47

def qp(sense:, offset: 0, col_cost:, col_lower:, col_upper:, row_lower:, row_upper:, a_format:, a_start:, a_index:, a_value:, q_format:, q_start:, q_index:, q_value:)
  num_col = col_cost.size
  num_row = row_lower.size
  num_nz = a_index.size
  q_num_nz = q_index.size
  a_format = FFI::MATRIX_FORMAT.fetch(a_format)
  q_format = FFI::MATRIX_FORMAT.fetch(q_format)
  sense = FFI::OBJ_SENSE.fetch(sense)

  model = Model.new
  check_status FFI.Highs_passModel(
    model, num_col, num_row, num_nz, q_num_nz, a_format, q_format, sense, offset,
    DoubleArray.new(num_col, col_cost), DoubleArray.new(num_col, col_lower), DoubleArray.new(num_col, col_upper),
    DoubleArray.new(num_row, row_lower), DoubleArray.new(num_row, row_upper),
    IntArray.new(a_start.size, a_start), IntArray.new(num_nz, a_index), DoubleArray.new(num_nz, a_value),
    IntArray.new(q_start.size, q_start), IntArray.new(q_num_nz, q_index), DoubleArray.new(q_num_nz, q_value), nil
  )
  model
end

#qp_call(**options) ⇒ Object



67
68
69
# File 'lib/highs/methods.rb', line 67

def qp_call(**options)
  qp(**options).solve
end

#read(filename) ⇒ Object



71
72
73
74
75
# File 'lib/highs/methods.rb', line 71

def read(filename)
  model = Model.new
  check_status FFI.Highs_readModel(model, +filename)
  model
end