From bb1ea5d1517935af9ddd5aa74ed12fffc373f0fb Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Sat, 5 Oct 2024 21:42:44 -0700 Subject: [PATCH] Reapply "Attempted fix" This reverts commit 7999d7464e04d6ab9e6b67df204a7f0f3bbe1cf2. --- lib/or-tools.rb | 2 +- lib/or_tools/constant.rb | 4 +++- lib/or_tools/linear_expr.rb | 6 +++++- lib/or_tools/product_cst.rb | 4 +++- lib/or_tools/sum_array.rb | 4 +++- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/or-tools.rb b/lib/or-tools.rb index 884d571..3ca94af 100644 --- a/lib/or-tools.rb +++ b/lib/or-tools.rb @@ -5,7 +5,6 @@ require_relative "or_tools/comparison" require_relative "or_tools/comparison_operators" require_relative "or_tools/bool_var" -require_relative "or_tools/constant" require_relative "or_tools/cp_model" require_relative "or_tools/cp_solver" require_relative "or_tools/cp_solver_solution_callback" @@ -13,6 +12,7 @@ require_relative "or_tools/knapsack_solver" require_relative "or_tools/linear_constraint" require_relative "or_tools/linear_expr" +require_relative "or_tools/constant" require_relative "or_tools/mp_variable" require_relative "or_tools/product_cst" require_relative "or_tools/routing_index_manager" diff --git a/lib/or_tools/constant.rb b/lib/or_tools/constant.rb index fbeebe0..4a58cda 100644 --- a/lib/or_tools/constant.rb +++ b/lib/or_tools/constant.rb @@ -1,5 +1,7 @@ module ORTools - class Constant < LinearExpr + class Constant + include LinearExprUtils + def initialize(val) @val = val end diff --git a/lib/or_tools/linear_expr.rb b/lib/or_tools/linear_expr.rb index 3d05657..b910f10 100644 --- a/lib/or_tools/linear_expr.rb +++ b/lib/or_tools/linear_expr.rb @@ -1,5 +1,5 @@ module ORTools - class LinearExpr + module LinearExprUtils def solution_value coeffs.sum { |var, coeff| var.solution_value * coeff } end @@ -82,4 +82,8 @@ def coerce(other) end end end + + class LinearExpr + include LinearExprUtils + end end diff --git a/lib/or_tools/product_cst.rb b/lib/or_tools/product_cst.rb index 48e1d94..704f55f 100644 --- a/lib/or_tools/product_cst.rb +++ b/lib/or_tools/product_cst.rb @@ -1,5 +1,7 @@ module ORTools - class ProductCst < LinearExpr + class ProductCst + include LinearExprUtils + attr_reader :expr, :coef def initialize(expr, coef) diff --git a/lib/or_tools/sum_array.rb b/lib/or_tools/sum_array.rb index dc6accc..7a2792f 100644 --- a/lib/or_tools/sum_array.rb +++ b/lib/or_tools/sum_array.rb @@ -1,5 +1,7 @@ module ORTools - class SumArray < LinearExpr + class SumArray + include LinearExprUtils + attr_reader :array def initialize(array)