or-tools 0.16.0 → 0.16.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a2c9e5edffd049efefd022fbb2d8473e922adb0d2d4bc7ca03fa87ec823929be
4
- data.tar.gz: 9825d9ab9fe616f263a8c5bfa23f57795fee798c486ef6ad6aa34bd4c47a5dac
3
+ metadata.gz: 63a926d63d95220ccee1d6861a26fdc96787a209210cf8473bc44855cb62f57d
4
+ data.tar.gz: 90a2bd6c3f72e759e22c104cfba792c39352d9908f3735fc17ca3ef15ca156db
5
5
  SHA512:
6
- metadata.gz: 53958c2e8aff5a55240cc19b8423d5c6cd8244214b26a79d969fe920f8faab2ad354ff7ef62039b05071d7b166436696152ffd141dff68451f8c09f8d119d83f
7
- data.tar.gz: 7abb3a8c5507f11796743b505351f285cbad89ab366fda35ae6b084f1835dcab8905f02fcb91e091bbeb142d097a8b314aadddc51a94d8285d257b6601e2e769
6
+ metadata.gz: b73722ccaa5d9700513c633dce30fa73d748431790c45c6bc77afa50375322c312578de81cd90128bfc0d2f0baff289094dba555e81c4dcbfb4137fb427add85
7
+ data.tar.gz: 99d4db8c29b87db1e6697b1c8e5bb6475ea41e4ec7c85f05ab9ee0510c5484614d055745704a7b7ba1d3c39930bf8bcf1a98174ad68ec0ca197dac70deb72eb9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 0.16.2 (2026-01-02)
2
+
3
+ - Fixed error with Rice 4.8
4
+
5
+ ## 0.16.1 (2025-10-26)
6
+
7
+ - Added `add_allowed_assignments` and `add_forbidden_assignments` methods to `CpModel`
8
+ - Fixed error with Rice 4.7
9
+
1
10
  ## 0.16.0 (2025-06-19)
2
11
 
3
12
  - Updated OR-Tools to 9.14
@@ -20,7 +20,11 @@ namespace Rice::detail {
20
20
  template<>
21
21
  class From_Ruby<KnapsackSolver::SolverType> {
22
22
  public:
23
- Convertible is_convertible(VALUE value) { return Convertible::Cast; }
23
+ From_Ruby() = default;
24
+
25
+ explicit From_Ruby(Arg* arg) : arg_(arg) { }
26
+
27
+ double is_convertible(VALUE value) { return Convertible::Exact; }
24
28
 
25
29
  KnapsackSolver::SolverType convert(VALUE x) {
26
30
  auto s = Symbol(x).str();
@@ -30,6 +34,9 @@ namespace Rice::detail {
30
34
  throw std::runtime_error("Unknown solver type: " + s);
31
35
  }
32
36
  }
37
+
38
+ private:
39
+ Arg* arg_ = nullptr;
33
40
  };
34
41
  } // namespace Rice::detail
35
42
 
@@ -9,6 +9,7 @@
9
9
  using operations_research::Domain;
10
10
  using operations_research::sat::BoolVar;
11
11
  using operations_research::sat::Constraint;
12
+ using operations_research::sat::TableConstraint;
12
13
  using operations_research::sat::CpModelBuilder;
13
14
  using operations_research::sat::CpSolverResponse;
14
15
  using operations_research::sat::CpSolverStatus;
@@ -39,7 +40,11 @@ namespace Rice::detail {
39
40
  template<>
40
41
  class From_Ruby<LinearExpr> {
41
42
  public:
42
- Convertible is_convertible(VALUE value) { return Convertible::Cast; }
43
+ From_Ruby() = default;
44
+
45
+ explicit From_Ruby(Arg* arg) : arg_(arg) { }
46
+
47
+ double is_convertible(VALUE value) { return Convertible::Exact; }
43
48
 
44
49
  LinearExpr convert(VALUE v) {
45
50
  LinearExpr expr;
@@ -62,6 +67,9 @@ namespace Rice::detail {
62
67
 
63
68
  return expr;
64
69
  }
70
+
71
+ private:
72
+ Arg* arg_ = nullptr;
65
73
  };
66
74
  } // namespace Rice::detail
67
75
 
@@ -103,6 +111,13 @@ void init_constraint(Rice::Module& m) {
103
111
  }
104
112
  });
105
113
 
114
+ Rice::define_class_under<TableConstraint, Constraint>(m, "SatTableConstraint")
115
+ .define_method(
116
+ "add_tuple",
117
+ [](TableConstraint& self, std::vector<int64_t> tuple) {
118
+ self.AddTuple(tuple);
119
+ });
120
+
106
121
  rb_cBoolVar = Rice::define_class_under<BoolVar>(m, "SatBoolVar")
107
122
  .define_method("name", &BoolVar::Name)
108
123
  .define_method("index", &BoolVar::index)
@@ -251,6 +266,16 @@ void init_constraint(Rice::Module& m) {
251
266
  [](CpModelBuilder& self, std::vector<IntVar> vars) {
252
267
  return self.AddAllDifferent(vars);
253
268
  })
269
+ .define_method(
270
+ "add_allowed_assignments",
271
+ [](CpModelBuilder& self, std::vector<LinearExpr> expressions) {
272
+ return self.AddAllowedAssignments(expressions);
273
+ })
274
+ .define_method(
275
+ "add_forbidden_assignments",
276
+ [](CpModelBuilder& self, std::vector<LinearExpr> expressions) {
277
+ return self.AddForbiddenAssignments(expressions);
278
+ })
254
279
  .define_method(
255
280
  "add_inverse_constraint",
256
281
  [](CpModelBuilder& self, std::vector<IntVar> variables, std::vector<IntVar> inverse_variables) {
@@ -391,7 +416,7 @@ void init_constraint(Rice::Module& m) {
391
416
  auto a = Array();
392
417
  auto assumptions = self.sufficient_assumptions_for_infeasibility();
393
418
  for (const auto& v : assumptions) {
394
- a.push(v);
419
+ a.push(v, false);
395
420
  }
396
421
  return a;
397
422
  });
@@ -6,7 +6,7 @@ $CXXFLAGS << " -std=c++17 $(optflags) -DUSE_CBC -DOR_PROTO_DLL="
6
6
  $CXXFLAGS << " -Wall -Wextra"
7
7
 
8
8
  # hide or-tools warnings
9
- $CXXFLAGS << " -Wno-sign-compare -Wno-ignored-qualifiers -Wno-unused-parameter -Wno-missing-field-initializers"
9
+ $CXXFLAGS << " -Wno-sign-compare -Wno-ignored-qualifiers -Wno-unused-parameter -Wno-missing-field-initializers -Wno-deprecated-declarations"
10
10
 
11
11
  # hide Rice warnings
12
12
  $CXXFLAGS << " -Wno-unused-private-field -Wno-implicit-fallthrough"
@@ -26,7 +26,11 @@ namespace Rice::detail {
26
26
 
27
27
  template<>
28
28
  struct From_Ruby<MPSolver::OptimizationProblemType> {
29
- Convertible is_convertible(VALUE value) { return Convertible::Cast; }
29
+ From_Ruby() = default;
30
+
31
+ explicit From_Ruby(Arg* arg) : arg_(arg) { }
32
+
33
+ double is_convertible(VALUE value) { return Convertible::Exact; }
30
34
 
31
35
  static MPSolver::OptimizationProblemType convert(VALUE x) {
32
36
  auto s = Symbol(x).str();
@@ -38,6 +42,9 @@ namespace Rice::detail {
38
42
  throw std::runtime_error("Unknown optimization problem type: " + s);
39
43
  }
40
44
  }
45
+
46
+ private:
47
+ Arg* arg_ = nullptr;
41
48
  };
42
49
  } // namespace Rice::detail
43
50
 
@@ -25,7 +25,11 @@ namespace Rice::detail {
25
25
 
26
26
  template<>
27
27
  struct From_Ruby<SolverType> {
28
- Convertible is_convertible(VALUE value) { return Convertible::Cast; }
28
+ From_Ruby() = default;
29
+
30
+ explicit From_Ruby(Arg* arg) : arg_(arg) { }
31
+
32
+ double is_convertible(VALUE value) { return Convertible::Exact; }
29
33
 
30
34
  static SolverType convert(VALUE x) {
31
35
  auto s = Symbol(x).str();
@@ -53,6 +57,9 @@ namespace Rice::detail {
53
57
  throw std::runtime_error("Unknown solver type: " + s);
54
58
  }
55
59
  }
60
+
61
+ private:
62
+ Arg* arg_ = nullptr;
56
63
  };
57
64
  } // namespace Rice::detail
58
65
 
@@ -61,7 +68,11 @@ void init_math_opt(Rice::Module& m) {
61
68
 
62
69
  Rice::define_class_under<Variable>(mathopt, "Variable")
63
70
  .define_method("id", &Variable::id)
64
- .define_method("name", &Variable::name)
71
+ .define_method(
72
+ "name",
73
+ [](Variable& self) {
74
+ return std::string(self.name());
75
+ })
65
76
  .define_method(
66
77
  "_eql?",
67
78
  [](Variable& self, Variable &other) {
@@ -47,7 +47,7 @@ void init_network_flows(Rice::Module& m) {
47
47
 
48
48
  Array ret;
49
49
  for (const auto& it : result) {
50
- ret.push(it);
50
+ ret.push(it, false);
51
51
  }
52
52
  return ret;
53
53
  })
@@ -59,7 +59,7 @@ void init_network_flows(Rice::Module& m) {
59
59
 
60
60
  Array ret;
61
61
  for (const auto& it : result) {
62
- ret.push(it);
62
+ ret.push(it, false);
63
63
  }
64
64
  return ret;
65
65
  });
@@ -36,20 +36,63 @@ namespace Rice::detail {
36
36
  template<>
37
37
  class From_Ruby<RoutingNodeIndex> {
38
38
  public:
39
- Convertible is_convertible(VALUE value) { return Convertible::Cast; }
39
+ From_Ruby() = default;
40
+
41
+ explicit From_Ruby(Arg* arg) : arg_(arg) { }
42
+
43
+ double is_convertible(VALUE value) { return Convertible::Exact; }
40
44
 
41
45
  RoutingNodeIndex convert(VALUE x) {
42
46
  const RoutingNodeIndex index{From_Ruby<int>().convert(x)};
43
47
  return index;
44
48
  }
49
+
50
+ private:
51
+ Arg* arg_ = nullptr;
45
52
  };
46
53
 
47
54
  template<>
48
55
  class To_Ruby<RoutingNodeIndex> {
49
56
  public:
57
+ To_Ruby() = default;
58
+
59
+ explicit To_Ruby(Arg* arg) : arg_(arg) { }
60
+
50
61
  VALUE convert(RoutingNodeIndex const & x) {
51
62
  return To_Ruby<int>().convert(x.value());
52
63
  }
64
+
65
+ private:
66
+ Arg* arg_ = nullptr;
67
+ };
68
+
69
+ template<>
70
+ struct Type<RoutingModel::PenaltyCostBehavior> {
71
+ static bool verify() { return true; }
72
+ };
73
+
74
+ template<>
75
+ class From_Ruby<RoutingModel::PenaltyCostBehavior> {
76
+ public:
77
+ From_Ruby() = default;
78
+
79
+ explicit From_Ruby(Arg* arg) : arg_(arg) { }
80
+
81
+ double is_convertible(VALUE value) { return Convertible::Exact; }
82
+
83
+ RoutingModel::PenaltyCostBehavior convert(VALUE x) {
84
+ auto s = Symbol(x).str();
85
+ if (s == "penalize_once") {
86
+ return RoutingModel::PenaltyCostBehavior::PENALIZE_ONCE;
87
+ } else if (s == "penalize_per_inactive") {
88
+ return RoutingModel::PenaltyCostBehavior::PENALIZE_PER_INACTIVE;
89
+ } else {
90
+ throw std::runtime_error("Unknown penalty cost behavior: " + s);
91
+ }
92
+ }
93
+
94
+ private:
95
+ Arg* arg_ = nullptr;
53
96
  };
54
97
  } // namespace Rice::detail
55
98
 
@@ -62,7 +105,7 @@ void init_routing(Rice::Module& m) {
62
105
  rb_cRoutingSearchParameters
63
106
  .define_method(
64
107
  "first_solution_strategy=",
65
- [](RoutingSearchParameters& self, Symbol value) {
108
+ [](RoutingSearchParameters& self, Object value) {
66
109
  auto s = Symbol(value).str();
67
110
 
68
111
  FirstSolutionStrategy::Value v;
@@ -102,7 +145,7 @@ void init_routing(Rice::Module& m) {
102
145
  })
103
146
  .define_method(
104
147
  "local_search_metaheuristic=",
105
- [](RoutingSearchParameters& self, Symbol value) {
148
+ [](RoutingSearchParameters& self, Object value) {
106
149
  auto s = Symbol(value).str();
107
150
 
108
151
  LocalSearchMetaheuristic::Value v;
@@ -333,7 +376,7 @@ void init_routing(Rice::Module& m) {
333
376
  .define_method("add_resource_group", &RoutingModel::AddResourceGroup)
334
377
  .define_method("dimension_resource_group_indices", &RoutingModel::GetDimensionResourceGroupIndices)
335
378
  .define_method("dimension_resource_group_index", &RoutingModel::GetDimensionResourceGroupIndex)
336
- .define_method("add_disjunction", &RoutingModel::AddDisjunction, Rice::Arg("_indices"), Rice::Arg("_penalty"), Rice::Arg("_max_cardinality") = static_cast<int64_t>(1), Rice::Arg("_penalty_cost_behavior") = RoutingModel::PenaltyCostBehavior::PENALIZE_ONCE)
379
+ .define_method("_add_disjunction", &RoutingModel::AddDisjunction)
337
380
  .define_method("disjunction_indices", &RoutingModel::GetDisjunctionIndices)
338
381
  .define_method("disjunction_penalty", &RoutingModel::GetDisjunctionPenalty)
339
382
  .define_method("disjunction_max_cardinality", &RoutingModel::GetDisjunctionMaxCardinality)
@@ -36,12 +36,12 @@ else
36
36
  elsif os == "ubuntu" && os_version == "20.04" && !arm
37
37
  filename = "or-tools_amd64_ubuntu-20.04_cpp_v#{version}.tar.gz"
38
38
  checksum = "7705a7c11e0db4ec1d7841e184acd204787174c6cbdb2fbd81169823ed148c6c"
39
- elsif os == "debian" && os_version == "11" && !arm
40
- filename = "or-tools_amd64_debian-11_cpp_v#{version}.tar.gz"
41
- checksum = "646b53e8d355290c4627d6bad0d36baeff38dc43605d317ac02cb811688d4dd2"
42
39
  elsif os == "debian" && os_version == "12" && !arm
43
40
  filename = "or-tools_amd64_debian-12_cpp_v#{version}.tar.gz"
44
41
  checksum = "285e8ec3a3399e45cdb4f67f48d4b65dbfa9c013b29036d409c72f96f0f34ab9"
42
+ elsif os == "debian" && os_version == "11" && !arm
43
+ filename = "or-tools_amd64_debian-11_cpp_v#{version}.tar.gz"
44
+ checksum = "646b53e8d355290c4627d6bad0d36baeff38dc43605d317ac02cb811688d4dd2"
45
45
  elsif os == "arch" && !arm
46
46
  filename = "or-tools_amd64_archlinux_cpp_v#{version}.tar.gz"
47
47
  checksum = "6be039a13c3be7a3dbcdc413d455b43bba4590ce38859062898835effefb5ca4"
@@ -17,5 +17,9 @@ module ORTools
17
17
  search_parameters.log_search = log_search unless log_search.nil?
18
18
  solve_with_parameters(search_parameters)
19
19
  end
20
+
21
+ def add_disjunction(indices, penalty, max_cardinality = 1, penalty_cost_behavior = :penalize_once)
22
+ _add_disjunction(indices, penalty, max_cardinality, penalty_cost_behavior)
23
+ end
20
24
  end
21
25
  end
@@ -1,3 +1,3 @@
1
1
  module ORTools
2
- VERSION = "0.16.0"
2
+ VERSION = "0.16.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: or-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.16.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 4.5.0
18
+ version: '4.8'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: 4.5.0
25
+ version: '4.8'
26
26
  email: andrew@ankane.org
27
27
  executables: []
28
28
  extensions:
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  requirements: []
88
- rubygems_version: 3.6.7
88
+ rubygems_version: 4.0.3
89
89
  specification_version: 4
90
90
  summary: Operations research tools for Ruby
91
91
  test_files: []