-
Notifications
You must be signed in to change notification settings - Fork 161
Add semi continuous variables support #1096
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
8181737
0a21c31
5a91abd
82532e6
0480e4b
b2a9788
88f8908
c3c1eb3
6b429a4
c6111eb
2eafd9c
f7a32fe
48ff3de
1e261ec
9f1d9c8
6b93e5c
64d6265
4ca42b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,9 +87,14 @@ void populate_from_mps_data_model(optimization_problem_interface_t<i_t, f_t>* pr | |
| if (!char_variable_types.empty()) { | ||
| std::vector<var_t> enum_variable_types(char_variable_types.size()); | ||
| for (size_t i = 0; i < char_variable_types.size(); ++i) { | ||
| enum_variable_types[i] = (char_variable_types[i] == 'I' || char_variable_types[i] == 'B') | ||
| ? var_t::INTEGER | ||
| : var_t::CONTINUOUS; | ||
| const char c = char_variable_types[i]; | ||
| if (c == 'I' || c == 'B') { | ||
| enum_variable_types[i] = var_t::INTEGER; | ||
| } else if (c == 'S') { | ||
| enum_variable_types[i] = var_t::SEMI_CONTINUOUS; | ||
| } else { | ||
| enum_variable_types[i] = var_t::CONTINUOUS; | ||
| } | ||
| } | ||
| problem->set_variable_types(enum_variable_types.data(), enum_variable_types.size()); | ||
| // Problem category (LP/MIP/IP) is auto-detected by set_variable_types | ||
|
|
@@ -253,7 +258,9 @@ void populate_from_data_model_view(optimization_problem_interface_t<i_t, f_t>* p | |
| data_model->get_variable_types().data() + data_model->get_variable_types().size(), | ||
| enum_variable_types.begin(), | ||
| [](const auto val) -> var_t { | ||
| return (val == 'I' || val == 'B') ? var_t::INTEGER : var_t::CONTINUOUS; | ||
| if (val == 'I' || val == 'B') return var_t::INTEGER; | ||
| if (val == 'S') return var_t::SEMI_CONTINUOUS; | ||
| return var_t::CONTINUOUS; | ||
|
Comment on lines
+261
to
+263
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check if MPS writer handles 'S' type variables for semi-continuous bounds
rg -n "'S'" cpp/libmps_parser/src/mps_writer.cpp
# Check how variable types are handled in the writer
rg -n -C3 "variable_types" cpp/libmps_parser/src/mps_writer.cpp | head -60Repository: NVIDIA/cuopt Length of output: 3159 🏁 Script executed: #!/bin/bash
# Verify the exact file and lines mentioned in the review
wc -l cpp/include/cuopt/linear_programming/optimization_problem_utils.hpp
sed -n '255,270p' cpp/include/cuopt/linear_programming/optimization_problem_utils.hpp
# Check for any 'SC' bounds handling in MPS writer
rg -n "'SC'" cpp/libmps_parser/src/mps_writer.cpp
# Check for semi-continuous handling anywhere in the writer
rg -n -i "semi" cpp/libmps_parser/src/mps_writer.cpp
# Get full context of bounds writing section
sed -n '335,370p' cpp/libmps_parser/src/mps_writer.cppRepository: NVIDIA/cuopt Length of output: 2640 🏁 Script executed: #!/bin/bash
# Search for any comments about semi-continuous in MPS writer
rg -n -i "semi\|sc bounds\|bound.*type" cpp/libmps_parser/src/mps_writer.cpp | head -20
# Check the MPS data model to understand how SC is meant to be handled
rg -n "'S'" cpp/libmps_parser/src/ -A2 -B2 | head -40
# Look at comments/docs about MPS writer scope
head -50 cpp/libmps_parser/src/mps_writer.cppRepository: NVIDIA/cuopt Length of output: 1905 Code at lines 261-263 is correct; MPS writer lacks semi-continuous serialization. The lambda correctly converts the 'S' character to 🤖 Prompt for AI Agents |
||
| }); | ||
| problem->set_variable_types(enum_variable_types.data(), enum_variable_types.size()); | ||
| // Problem category (LP/MIP/IP) is auto-detected by set_variable_types | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| #include <cmath> | ||
| #include <cstdint> | ||
| #include <filesystem> | ||
| #include <fstream> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check if fstream types/functions are used in the test file
rg -n "ifstream|ofstream|fstream\b" cpp/libmps_parser/tests/mps_parser_test.cppRepository: NVIDIA/cuopt Length of output: 77 Remove unused The 🤖 Prompt for AI Agents |
||
| #include <sstream> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
@@ -422,6 +423,33 @@ TEST(mps_bounds, upper_inf_var_bound) | |
| EXPECT_EQ(std::numeric_limits<double>::infinity(), mps.variable_upper_bounds[1]); | ||
| } | ||
|
|
||
| TEST(mps_bounds, semi_continuous_var_bounds_from_dataset) | ||
| { | ||
| struct Case { | ||
| const char* file; | ||
| int n_vars; | ||
| double lower; | ||
| double upper; | ||
| }; | ||
| const std::vector<Case> cases = { | ||
| {"mip/sc_standard.mps", 2, 2.0, 10.0}, | ||
| {"mip/sc_lb_zero.mps", 2, 0.0, 10.0}, | ||
| {"mip/sc_no_ub.mps", 2, 2.0, 1e30}, | ||
| }; | ||
|
|
||
| for (const auto& c : cases) { | ||
| SCOPED_TRACE(c.file); | ||
| auto mps = read_from_mps(c.file, false); | ||
|
|
||
| ASSERT_EQ(c.n_vars, static_cast<int>(mps.var_types.size())); | ||
| EXPECT_EQ('S', mps.var_types[0]); | ||
| ASSERT_EQ(c.n_vars, static_cast<int>(mps.variable_lower_bounds.size())); | ||
| ASSERT_EQ(c.n_vars, static_cast<int>(mps.variable_upper_bounds.size())); | ||
| EXPECT_DOUBLE_EQ(c.lower, mps.variable_lower_bounds[0]); | ||
| EXPECT_DOUBLE_EQ(c.upper, mps.variable_upper_bounds[0]); | ||
| } | ||
| } | ||
|
|
||
| TEST(mps_ranges, fixed_ranges) | ||
| { | ||
| std::string file = "linear_programming/good-mps-fixed-ranges.mps"; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the remote/grpc enum mappers in the same change.
Line 23 adds
var_t::SEMI_CONTINUOUS, butcpp/src/grpc/grpc_problem_mapper.cpp:108-119,cpp/src/grpc/grpc_problem_mapper.cpp:131-141, andcpp/src/grpc/grpc_problem_mapper.cpp:638-648still only mapCONTINUOUS/INTEGERand throw in the default branch. Any remote solve or chunked transfer that carries an SC variable will still fail at runtime.🤖 Prompt for AI Agents