Skip to content

Commit

Permalink
Fixed bad_any_cast
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Oct 6, 2024
1 parent 58891cc commit 5fe649b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
5 changes: 1 addition & 4 deletions ext/or-tools/linear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ namespace Rice::detail
void init_linear(Rice::Module& m) {
Rice::define_class_under<LinearRange>(m, "LinearRange");

auto rb_cLinearExpr = Rice::define_class_under<LinearExpr>(m, "LinearExpr");
rb_cLinearExpr.define_constructor(Rice::Constructor<LinearExpr>());

Rice::define_class_under<MPVariable, LinearExpr>(m, "MPVariable")
Rice::define_class_under<MPVariable>(m, "MPVariable")
.define_method("name", &MPVariable::name)
.define_method("solution_value", &MPVariable::solution_value);

Expand Down
2 changes: 1 addition & 1 deletion lib/or-tools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
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"
require_relative "or_tools/cp_solver_solution_callback"
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"
Expand Down
6 changes: 5 additions & 1 deletion lib/or_tools/linear_expr.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ORTools
class LinearExpr
module LinearExprMethods
def solution_value
coeffs.sum { |var, coeff| var.solution_value * coeff }
end
Expand Down Expand Up @@ -82,4 +82,8 @@ def coerce(other)
end
end
end

class LinearExpr
include LinearExprMethods
end
end
4 changes: 3 additions & 1 deletion lib/or_tools/mp_variable.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 5fe649b

Please sign in to comment.