diff --git a/ext/or-tools/linear.cpp b/ext/or-tools/linear.cpp index 8ebf163..72fc632 100644 --- a/ext/or-tools/linear.cpp +++ b/ext/or-tools/linear.cpp @@ -47,10 +47,7 @@ namespace Rice::detail void init_linear(Rice::Module& m) { Rice::define_class_under(m, "LinearRange"); - auto rb_cLinearExpr = Rice::define_class_under(m, "LinearExpr"); - rb_cLinearExpr.define_constructor(Rice::Constructor()); - - Rice::define_class_under(m, "MPVariable") + Rice::define_class_under(m, "MPVariable") .define_method("name", &MPVariable::name) .define_method("solution_value", &MPVariable::solution_value); diff --git a/lib/or-tools.rb b/lib/or-tools.rb index 884d571..300d74c 100644 --- a/lib/or-tools.rb +++ b/lib/or-tools.rb @@ -5,6 +5,7 @@ require_relative "or_tools/comparison" require_relative "or_tools/comparison_operators" require_relative "or_tools/bool_var" +require_relative "or_tools/linear_expr" require_relative "or_tools/constant" require_relative "or_tools/cp_model" require_relative "or_tools/cp_solver" @@ -12,7 +13,6 @@ require_relative "or_tools/int_var" require_relative "or_tools/knapsack_solver" require_relative "or_tools/linear_constraint" -require_relative "or_tools/linear_expr" 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/linear_expr.rb b/lib/or_tools/linear_expr.rb index 3d05657..015da13 100644 --- a/lib/or_tools/linear_expr.rb +++ b/lib/or_tools/linear_expr.rb @@ -1,5 +1,5 @@ module ORTools - class LinearExpr + module LinearExprMethods 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 LinearExprMethods + end end diff --git a/lib/or_tools/mp_variable.rb b/lib/or_tools/mp_variable.rb index b9b2ad5..e8572f7 100644 --- a/lib/or_tools/mp_variable.rb +++ b/lib/or_tools/mp_variable.rb @@ -1,5 +1,7 @@ module ORTools - class MPVariable < LinearExpr + class MPVariable + include LinearExprMethods + def add_self_to_coeff_map_or_stack(coeffs, multiplier, stack) coeffs[self] += multiplier end