highs 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6e29b694c68a7f26a7674c5dad300e17b12c5ce3d2a961f33bec5a4663ff1c4
4
- data.tar.gz: 6f9944e2ceed6395a75372e9fecb5b7d69e42133476eeaef1150146ec28f6532
3
+ metadata.gz: 0a46946b06578fabfbeefcc9c48bb423db4df21a3fec2256ea45f677d515318e
4
+ data.tar.gz: 0d109b3fa7b03111b5340dfee2f0608136e6fc5de81aba43fde395a01c8f4aff
5
5
  SHA512:
6
- metadata.gz: 2acd4b5fb27c2a6834cb2412d7b0a9b5c844a33957f6a45d7f776a6f8b89c5a3b8e160e5886de74445c3ca6b8e349fe33f6072a88130338956f0e3583eb2b937
7
- data.tar.gz: 721cbdcbbda13229ce1ae8393acd55a76bea821899119cd4c83126db19f727a8ad0005362b56efcd195b5f53a3d5d4d19662c18325a4d131b8302244ae45ca25
6
+ metadata.gz: d4994ef6fb41aa6f22b7fc1e1f6cadf87829faafdea50d8f8c0fb626170712219065ebd94875b458d91d7caa1ad2b951cdd602608c2285e09f85dda454be9c42
7
+ data.tar.gz: f275a812845405cfbe046b5e4b27593bb39cd1868037f965fa47f85c1434e06f71678c41eb2e6d0253cca4fb9c720aa8a0afe94dc56beb4b14a8965e4aa9abae
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.1.2 (2022-04-14)
2
+
3
+ - Added `verbose` and `time_limit` options to `solve` method
4
+ - Added support for symbol integrality
5
+
1
6
  ## 0.1.1 (2022-04-10)
2
7
 
3
8
  - Added objective value
data/README.md CHANGED
@@ -49,7 +49,7 @@ model =
49
49
  a_start: [0, 3],
50
50
  a_index: [0, 1, 2, 0, 1, 2],
51
51
  a_value: [2, 3, 2, 2, 4, 1],
52
- integrality: [1, 1]
52
+ integrality: [:integer, :continuous]
53
53
  )
54
54
  ```
55
55
 
@@ -93,6 +93,20 @@ Read a program from an MPS file
93
93
  model = Highs.read("model.mps")
94
94
  ```
95
95
 
96
+ ## Reference
97
+
98
+ Enable verbose logging
99
+
100
+ ```ruby
101
+ model.solve(verbose: true)
102
+ ```
103
+
104
+ Set the time limit in seconds
105
+
106
+ ```ruby
107
+ model.solve(time_limit: 30)
108
+ ```
109
+
96
110
  ## History
97
111
 
98
112
  View the [changelog](https://github.com/ankane/highs-ruby/blob/master/CHANGELOG.md)
data/lib/highs/ffi.rb CHANGED
@@ -12,15 +12,12 @@ module Highs
12
12
 
13
13
  # https://github.com/ERGO-Code/HiGHS/blob/master/src/interfaces/highs_c_api.h
14
14
 
15
- MODEL_STATUS = [
16
- :not_set, :load_error, :model_error, :presolve_error, :solve_error, :postsolve_error,
17
- :model_empty, :optimal, :infeasible, :unbounded_or_infeasible, :unbounded,
18
- :objective_bound, :objective_target, :time_limit, :iteration_limit, :unknown
19
- ]
20
-
21
- MATRIX_FORMAT = {
22
- colwise: 1,
23
- rowwise: 2
15
+ VAR_TYPE = {
16
+ continuous: 0,
17
+ integer: 1,
18
+ semi_continuous: 2,
19
+ semi_integer: 3,
20
+ implicit_integer: 4
24
21
  }
25
22
 
26
23
  OBJ_SENSE = {
@@ -28,6 +25,17 @@ module Highs
28
25
  maximize: -1
29
26
  }
30
27
 
28
+ MATRIX_FORMAT = {
29
+ colwise: 1,
30
+ rowwise: 2
31
+ }
32
+
33
+ MODEL_STATUS = [
34
+ :not_set, :load_error, :model_error, :presolve_error, :solve_error, :postsolve_error,
35
+ :model_empty, :optimal, :infeasible, :unbounded_or_infeasible, :unbounded,
36
+ :objective_bound, :objective_target, :time_limit, :iteration_limit, :unknown
37
+ ]
38
+
31
39
  BASIS_STATUS = [:lower, :basic, :upper, :zero, :nonbasic]
32
40
 
33
41
  typealias "HighsInt", "int"
@@ -50,6 +58,14 @@ module Highs
50
58
  extern "HighsInt Highs_passModel(void* highs, HighsInt num_col, HighsInt num_row, HighsInt num_nz, HighsInt q_num_nz, HighsInt a_format, HighsInt q_format, HighsInt sense, double offset, double* col_cost, double* col_lower, double* col_upper, double* row_lower, double* row_upper, HighsInt* a_start, HighsInt* a_index, double* a_value, HighsInt* q_start, HighsInt* q_index, double* q_value, HighsInt* integrality)"
51
59
  extern "HighsInt Highs_passHessian(void* highs, HighsInt dim, HighsInt num_nz, HighsInt format, HighsInt* start, HighsInt* index, double* value)"
52
60
  extern "HighsInt Highs_setBoolOptionValue(void* highs, char* option, HighsInt value)"
61
+ extern "HighsInt Highs_setIntOptionValue(void* highs, char* option, HighsInt value)"
62
+ extern "HighsInt Highs_setDoubleOptionValue(void* highs, char* option, double value)"
63
+ extern "HighsInt Highs_setStringOptionValue(void* highs, char* option, char* value)"
64
+ extern "HighsInt Highs_getBoolOptionValue(void* highs, char* option, HighsInt* value)"
65
+ extern "HighsInt Highs_getIntOptionValue(void* highs, char* option, HighsInt* value)"
66
+ extern "HighsInt Highs_getDoubleOptionValue(void* highs, char* option, double* value)"
67
+ extern "HighsInt Highs_getStringOptionValue(void* highs, char* option, char* value)"
68
+ extern "HighsInt Highs_getOptionType(void* highs, char* option, HighsInt* type)"
53
69
  extern "HighsInt Highs_getSolution(void* highs, double* col_value, double* col_dual, double* row_value, double* row_dual)"
54
70
  extern "HighsInt Highs_getBasis(void* highs, HighsInt* col_status, HighsInt* row_status)"
55
71
  extern "HighsInt Highs_getModelStatus(void* highs)"
data/lib/highs/methods.rb CHANGED
@@ -27,6 +27,7 @@ module Highs
27
27
  num_nz = a_index.size
28
28
  a_format = FFI::MATRIX_FORMAT.fetch(a_format)
29
29
  sense = FFI::OBJ_SENSE.fetch(sense)
30
+ integrality = integrality.map { |v| FFI::VAR_TYPE[v] || v }
30
31
 
31
32
  model = Model.new
32
33
  check_status FFI.Highs_passMip(
data/lib/highs/model.rb CHANGED
@@ -4,11 +4,13 @@ module Highs
4
4
  @ptr = FFI.Highs_create
5
5
  ObjectSpace.define_finalizer(self, self.class.finalize(@ptr))
6
6
 
7
- # TODO add option
8
7
  check_status FFI.Highs_setBoolOptionValue(@ptr, "output_flag", 0)
9
8
  end
10
9
 
11
- def solve
10
+ def solve(verbose: false, time_limit: nil)
11
+ num_col = FFI.Highs_getNumCol(@ptr)
12
+ num_row = FFI.Highs_getNumRow(@ptr)
13
+
12
14
  col_value = DoubleArray.new(num_col)
13
15
  col_dual = DoubleArray.new(num_col)
14
16
  row_value = DoubleArray.new(num_row)
@@ -16,7 +18,9 @@ module Highs
16
18
  col_basis = IntArray.new(num_col)
17
19
  row_basis = IntArray.new(num_row)
18
20
 
19
- check_status FFI.Highs_run(@ptr)
21
+ with_options(verbose: verbose, time_limit: time_limit) do
22
+ check_status FFI.Highs_run(@ptr)
23
+ end
20
24
  check_status FFI.Highs_getSolution(@ptr, col_value, col_dual, row_value, row_dual)
21
25
  check_status FFI.Highs_getBasis(@ptr, col_basis, row_basis)
22
26
  model_status = FFI.Highs_getModelStatus(@ptr)
@@ -48,16 +52,17 @@ module Highs
48
52
 
49
53
  private
50
54
 
51
- def num_col
52
- FFI.Highs_getNumCol(@ptr)
53
- end
54
-
55
- def num_row
56
- FFI.Highs_getNumRow(@ptr)
57
- end
58
-
59
55
  def check_status(status)
60
56
  Highs.send(:check_status, status)
61
57
  end
58
+
59
+ def with_options(verbose:, time_limit:)
60
+ check_status(FFI.Highs_setBoolOptionValue(@ptr, "output_flag", 1)) if verbose
61
+ check_status(FFI.Highs_setDoubleOptionValue(@ptr, "time_limit", time_limit)) if time_limit
62
+ yield
63
+ ensure
64
+ check_status(FFI.Highs_setBoolOptionValue(@ptr, "output_flag", 0)) if verbose
65
+ check_status(FFI.Highs_setDoubleOptionValue(@ptr, "time_limit", Float::INFINITY)) if time_limit
66
+ end
62
67
  end
63
68
  end
data/lib/highs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Highs
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: highs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-11 00:00:00.000000000 Z
11
+ date: 2022-04-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: andrew@ankane.org