or-tools 0.18.1 → 0.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/ext/or-tools/constraint.cpp +38 -10
- data/lib/or_tools/cp_solver.rb +60 -13
- data/lib/or_tools/cp_solver_solution_callback.rb +57 -2
- data/lib/or_tools/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 309c56f023b6cc67adcf41c3b8b41c491be25ff53b8fc59791370a8be3e97adb
|
|
4
|
+
data.tar.gz: af24caa0777d73df4b1ae089d40095534fe0186e7c479b376abc5b9172026dc7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f030d0b629a7193a121c237889a9c9b81a6f0a8167bdddeb02ce08a1bd221e27ba4e92c1b641008b12565f538671ceab4dc9bb36ebc6c217cb2b0adcdae4c7f0
|
|
7
|
+
data.tar.gz: c383519b49d6e844e086dc61122f2a6dc8732560c5838e3c5684b71972e5910d28d1ab06f5686170b437ff90a9f521ca54189b12ec188eed1cc9fed46c238890
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## 0.18.2 (2026-10-27)
|
|
2
|
+
|
|
3
|
+
- Added `add_at_most_one` and `add_exactly_one` methods to `CpModel`
|
|
4
|
+
- Added `objective?` and `clear_objective` methods to `CpModel`
|
|
5
|
+
- Added more methods to `CpSolver`
|
|
6
|
+
- Added more methods to `CpSolverSolutionCallback`
|
|
7
|
+
|
|
1
8
|
## 0.18.1 (2026-10-02)
|
|
2
9
|
|
|
3
10
|
- Added support for breaks for routing
|
data/ext/or-tools/constraint.cpp
CHANGED
|
@@ -755,6 +755,16 @@ void init_constraint(Rice::Module& m) {
|
|
|
755
755
|
[](CpModelBuilder& self, const std::vector<BoolVar>& literals) {
|
|
756
756
|
return self.AddBoolOr(literals);
|
|
757
757
|
})
|
|
758
|
+
.define_method(
|
|
759
|
+
"add_at_most_one",
|
|
760
|
+
[](CpModelBuilder& self, const std::vector<BoolVar>& literals) {
|
|
761
|
+
return self.AddAtMostOne(literals);
|
|
762
|
+
})
|
|
763
|
+
.define_method(
|
|
764
|
+
"add_exactly_one",
|
|
765
|
+
[](CpModelBuilder& self, const std::vector<BoolVar>& literals) {
|
|
766
|
+
return self.AddExactlyOne(literals);
|
|
767
|
+
})
|
|
758
768
|
.define_method(
|
|
759
769
|
"add_bool_and",
|
|
760
770
|
[](CpModelBuilder& self, const std::vector<BoolVar>& literals) {
|
|
@@ -875,6 +885,16 @@ void init_constraint(Rice::Module& m) {
|
|
|
875
885
|
[](CpModelBuilder& self, LinearExpr expr) {
|
|
876
886
|
self.Minimize(expr);
|
|
877
887
|
})
|
|
888
|
+
.define_method(
|
|
889
|
+
"clear_objective",
|
|
890
|
+
[](CpModelBuilder& self) {
|
|
891
|
+
self.ClearObjective();
|
|
892
|
+
})
|
|
893
|
+
.define_method(
|
|
894
|
+
"objective?",
|
|
895
|
+
[](CpModelBuilder& self) {
|
|
896
|
+
return self.HasObjective();
|
|
897
|
+
})
|
|
878
898
|
.define_method(
|
|
879
899
|
"add_hint",
|
|
880
900
|
[](CpModelBuilder& self, Object var, Object value) {
|
|
@@ -926,9 +946,23 @@ void init_constraint(Rice::Module& m) {
|
|
|
926
946
|
});
|
|
927
947
|
|
|
928
948
|
Rice::define_class_under<CpSolverResponse>(m, "CpSolverResponse")
|
|
929
|
-
.define_method("
|
|
930
|
-
.define_method("
|
|
949
|
+
.define_method("best_objective_bound", &CpSolverResponse::best_objective_bound)
|
|
950
|
+
.define_method("deterministic_time", &CpSolverResponse::deterministic_time)
|
|
951
|
+
.define_method("gap_integral", &CpSolverResponse::gap_integral)
|
|
952
|
+
.define_method("inner_objective_lower_bound", &CpSolverResponse::inner_objective_lower_bound)
|
|
953
|
+
.define_method("num_binary_propagations", &CpSolverResponse::num_binary_propagations)
|
|
954
|
+
.define_method("num_booleans", &CpSolverResponse::num_booleans)
|
|
931
955
|
.define_method("num_branches", &CpSolverResponse::num_branches)
|
|
956
|
+
.define_method("num_conflicts", &CpSolverResponse::num_conflicts)
|
|
957
|
+
.define_method("num_fixed_booleans", &CpSolverResponse::num_fixed_booleans)
|
|
958
|
+
.define_method("num_integer_propagations", &CpSolverResponse::num_integer_propagations)
|
|
959
|
+
.define_method("num_integers", &CpSolverResponse::num_integers)
|
|
960
|
+
.define_method("num_lp_iterations", &CpSolverResponse::num_lp_iterations)
|
|
961
|
+
.define_method("num_restarts", &CpSolverResponse::num_restarts)
|
|
962
|
+
.define_method("objective_value", &CpSolverResponse::objective_value)
|
|
963
|
+
.define_method("solution_info", &CpSolverResponse::solution_info)
|
|
964
|
+
.define_method("solve_log", &CpSolverResponse::solve_log)
|
|
965
|
+
.define_method("user_time", &CpSolverResponse::user_time)
|
|
932
966
|
.define_method("wall_time", &CpSolverResponse::wall_time)
|
|
933
967
|
.define_method(
|
|
934
968
|
"solution_integer_value",
|
|
@@ -956,17 +990,11 @@ void init_constraint(Rice::Module& m) {
|
|
|
956
990
|
throw std::runtime_error{"Unknown solver status"};
|
|
957
991
|
}
|
|
958
992
|
})
|
|
959
|
-
.define_method(
|
|
960
|
-
"solution_info",
|
|
961
|
-
[](CpSolverResponse& self) {
|
|
962
|
-
return self.solution_info();
|
|
963
|
-
})
|
|
964
993
|
.define_method(
|
|
965
994
|
"sufficient_assumptions_for_infeasibility",
|
|
966
995
|
[](CpSolverResponse& self) {
|
|
967
|
-
|
|
968
|
-
auto
|
|
969
|
-
for (const auto& v : assumptions) {
|
|
996
|
+
Array a;
|
|
997
|
+
for (const auto& v : self.sufficient_assumptions_for_infeasibility()) {
|
|
970
998
|
a.push(v, false);
|
|
971
999
|
}
|
|
972
1000
|
return a;
|
data/lib/or_tools/cp_solver.rb
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
require "forwardable"
|
|
2
|
-
|
|
3
1
|
module ORTools
|
|
4
2
|
class CpSolver
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
def parameters
|
|
4
|
+
@parameters ||= SatParameters.new
|
|
5
|
+
end
|
|
8
6
|
|
|
9
7
|
def solve(model, observer = nil)
|
|
10
8
|
@response = _solve(model, parameters, observer)
|
|
@@ -13,29 +11,78 @@ module ORTools
|
|
|
13
11
|
end
|
|
14
12
|
|
|
15
13
|
def value(var)
|
|
14
|
+
response = checked_response
|
|
15
|
+
|
|
16
16
|
# could also check solution_size == 0
|
|
17
|
-
unless [:feasible, :optimal].include?(
|
|
17
|
+
unless [:feasible, :optimal].include?(response.status)
|
|
18
18
|
# could return nil, but raise error like Python library
|
|
19
19
|
raise Error, "No solution found"
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
if var.is_a?(BoolVar)
|
|
23
|
-
_solution_boolean_value(
|
|
23
|
+
_solution_boolean_value(response, var)
|
|
24
24
|
else
|
|
25
|
-
_solution_integer_value(
|
|
25
|
+
_solution_integer_value(response, var)
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
def
|
|
30
|
-
|
|
29
|
+
def objective_value
|
|
30
|
+
checked_response.objective_value
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def best_objective_bound
|
|
34
|
+
checked_response.best_objective_bound
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def num_booleans
|
|
38
|
+
checked_response.num_booleans
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def num_conflicts
|
|
42
|
+
checked_response.num_conflicts
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def num_branches
|
|
46
|
+
checked_response.num_branches
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def num_binary_propagations
|
|
50
|
+
checked_response.num_binary_propagations
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def num_integer_propagations
|
|
54
|
+
checked_response.num_integer_propagations
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def deterministic_time
|
|
58
|
+
checked_response.deterministic_time
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def wall_time
|
|
62
|
+
checked_response.wall_time
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def user_time
|
|
66
|
+
checked_response.user_time
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def solve_log
|
|
70
|
+
checked_response.solve_log
|
|
31
71
|
end
|
|
32
72
|
|
|
33
73
|
def sufficient_assumptions_for_infeasibility
|
|
34
|
-
|
|
74
|
+
checked_response.sufficient_assumptions_for_infeasibility
|
|
35
75
|
end
|
|
36
76
|
|
|
37
|
-
def
|
|
38
|
-
|
|
77
|
+
def solution_info
|
|
78
|
+
checked_response.solution_info
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
private
|
|
82
|
+
|
|
83
|
+
def checked_response
|
|
84
|
+
raise "solve() has not been called." if @response.nil?
|
|
85
|
+
@response
|
|
39
86
|
end
|
|
40
87
|
end
|
|
41
88
|
end
|
|
@@ -3,6 +3,8 @@ module ORTools
|
|
|
3
3
|
attr_writer :response
|
|
4
4
|
|
|
5
5
|
def value(expr)
|
|
6
|
+
# TODO uncomment in 0.19.0
|
|
7
|
+
# raise "solve() has not been called." unless response?
|
|
6
8
|
case expr
|
|
7
9
|
when SatIntVar
|
|
8
10
|
@response&.solution_integer_value(expr)
|
|
@@ -13,12 +15,65 @@ module ORTools
|
|
|
13
15
|
end
|
|
14
16
|
end
|
|
15
17
|
|
|
16
|
-
def
|
|
17
|
-
|
|
18
|
+
def response?
|
|
19
|
+
!@response.nil?
|
|
18
20
|
end
|
|
19
21
|
|
|
20
22
|
def stop_search
|
|
23
|
+
# TODO uncomment in 0.19.0
|
|
24
|
+
# raise "solve() has not been called." unless response?
|
|
21
25
|
@stopped = true
|
|
22
26
|
end
|
|
27
|
+
|
|
28
|
+
def objective_value
|
|
29
|
+
# TODO uncomment in 0.19.0
|
|
30
|
+
# raise "solve() has not been called." unless response?
|
|
31
|
+
@response&.objective_value
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def best_objective_bound
|
|
35
|
+
raise "solve() has not been called." unless response?
|
|
36
|
+
@response.best_objective_bound
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def num_booleans
|
|
40
|
+
raise "solve() has not been called." unless response?
|
|
41
|
+
@response.num_booleans
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def num_conflicts
|
|
45
|
+
raise "solve() has not been called." unless response?
|
|
46
|
+
@response.num_conflicts
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def num_branches
|
|
50
|
+
raise "solve() has not been called." unless response?
|
|
51
|
+
@response.num_branches
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def num_integer_propagations
|
|
55
|
+
raise "solve() has not been called." unless response?
|
|
56
|
+
@response.num_integer_propagations
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def num_binary_propagations
|
|
60
|
+
raise "solve() has not been called." unless response?
|
|
61
|
+
@response.num_binary_propagations
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def deterministic_time
|
|
65
|
+
raise "solve() has not been called." unless response?
|
|
66
|
+
@response.deterministic_time
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def wall_time
|
|
70
|
+
raise "solve() has not been called." unless response?
|
|
71
|
+
@response.wall_time
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def user_time
|
|
75
|
+
raise "solve() has not been called." unless response?
|
|
76
|
+
@response.user_time
|
|
77
|
+
end
|
|
23
78
|
end
|
|
24
79
|
end
|
data/lib/or_tools/version.rb
CHANGED