diff --git a/ext/or-tools/math_opt.cpp b/ext/or-tools/math_opt.cpp index 9fc683c..77cc2cf 100644 --- a/ext/or-tools/math_opt.cpp +++ b/ext/or-tools/math_opt.cpp @@ -64,6 +64,7 @@ void init_math_opt(Rice::Module& m) { Rice::define_class_under(mathopt, "Variable") .define_method("id", &Variable::id) + .define_method("name", &Variable::name) .define_method( "_eql?", [](Variable& self, Variable &other) { diff --git a/test/math_opt_test.rb b/test/math_opt_test.rb index 68682cf..00793c4 100644 --- a/test/math_opt_test.rb +++ b/test/math_opt_test.rb @@ -74,4 +74,11 @@ def test_non_integer_solver end assert_equal "Glop does not support integer variables", error.message end + + def test_variable_inspect + model = ORTools::MathOpt::Model.new("getting_started_lp") + var = model.add_integer_variable(-1.0, 1.5, "x") + + assert_equal "x", var.inspect + end end