Replies: 3 comments 3 replies
-
Adding the C++ example to the examples directory could certainly be done and I will do that. But I guess the only thing that will be different from what is in the documentation you pointed to is an auto-generated, human-readable Makefile, which may be what you're really looking for. If you can be more specific about what is giving you trouble, I can try to help further. It may take me a few days to find the time to add the example. |
Beta Was this translation helpful? Give feedback.
-
Hi Ted, Thank you for responding so quickly! Here I have some files that do not compile using the C++ API Although I haven't changed it in the code yet to fit this case, I have an example that would be ideal for me to understand how to use the library for my problem: I could run this case in Mibs using this .mps and auxiliary file .aux: which are executed as follows: The output is: ========================================================Welcome to MibS (Mixed Integer Bilevel Solver)
|
Beta Was this translation helpful? Give feedback.
-
Hi, I am currently working on a working example for MibS in C++, since I need to use MibS in my research through its C++ API. The example models a min-max problem:
with
What I currently have is the following code: OsiCpxSolverInterface solver;
MibSModel mibs;
mibs.setSolver(&solver);
const double inf = solver.getInfinity();
const int xi_1 = 0;
const int xi_2 = 1;
const int y_1 = 2;
const int y_2 = 3;
CoinPackedMatrix matrix(false, 0, 4);
{
CoinPackedVector row;
row.insert(xi_1, 1);
row.insert(xi_2, 1);
matrix.appendRow(row);
}
{
CoinPackedVector row;
row.insert(y_1, -2);
row.insert(y_2, 1);
row.insert(xi_1, 3);
matrix.appendRow(row);
}
{
CoinPackedVector row;
row.insert(y_1, 3);
row.insert(y_2, 3);
row.insert(xi_1, -2);
row.insert(xi_2, 3);
matrix.appendRow(row);
}
std::vector<int> lower_level_variables_indices { y_1, y_2 };
std::vector<int> lower_level_constraints_indices { 1, 2 };
std::vector<double> lower_level_objective_coefficients { 2, 3 };
std::vector<int> upper_level_variables_indices { xi_1, xi_2 };
std::vector<int> upper_level_constraints_indices { 0 };
mibs.loadAuxiliaryData((int) lower_level_variables_indices.size(),
(int) lower_level_constraints_indices.size(),
lower_level_variables_indices.data(),
lower_level_constraints_indices.data(),
1.,
lower_level_objective_coefficients.data(),
(int) upper_level_variables_indices.size(),
(int) upper_level_constraints_indices.size(),
upper_level_variables_indices.data(),
upper_level_constraints_indices.data(),
0,
nullptr,
0,
nullptr,
nullptr,
nullptr);
std::vector<double> constraint_lower_bounds = { -inf, 0, 1 };
std::vector<double> constraint_upper_bounds = { 1, inf, inf };
std::vector<char> constraint_types = { 'L', 'G', 'G' };
std::vector<char> variable_types = { 'B', 'B', 'B', 'B' };
std::vector<double> variable_lower_bounds = { 0, 0, 0, 0 };
std::vector<double> variable_upper_bounds = { 1, 1, 1, 1 };
std::vector<double> objective = { 0, 0, -2, -3 };
mibs.loadProblemData(matrix,
variable_lower_bounds.data(),
variable_upper_bounds.data(),
objective.data(),
constraint_lower_bounds.data(),
constraint_upper_bounds.data(),
variable_types.data(),
1.,
inf,
constraint_types.data());
std::string arg = "mibs";
int argc = 1;
char** argv = new char* [1];
argv[0] = arg.data();
AlpsKnowledgeBrokerSerial broker(argc, argv, mibs);
broker.search(&mibs); Unfortunately, this code does not work so far and I would like to understand what I am doing wrong here. When I run this code, I get the following exception (Note that I am using OsiCpxSolverInterface here): == Welcome to the Abstract Library for Parallel Search (ALPS)
== Copyright 2000-2023 Lehigh University and others
== All Rights Reserved.
== Distributed under the Eclipse Public License 1.0
== Version: 1.5
== Build Date: Jan 31 2024
=======================================
Problem structure
=======================================
Number of UL Variables (total): 2
Number of UL Variables (integer): 2
Number of LL Variables (total): 2
Number of LL Variables (integer): 2
Number of UL Rows: 2
Number of LL Rows: 2
This instance is a pure integer problem.
All upper level variables are binary.
All lower level variables are binary.
Coefficient matrix of lower level variables in upper level problem is non-negative.
Coefficient matrix of lower level variables in upper level problem is non-negative.
Degree of objective alignment: 0
=======================================
Parameter Settings
=======================================
Branching strategy is to branch only on variable with fractional values.
Benders binary cut generator is on.
Generalized no-good cut generator is on.
Second level problem will be solved when linking variables are fixed
or first and second level variables are integer.
Upper bounding problem will be solved when linking variables are fixed.
Linking solution pool will be used.
Blis0043I Objective coefficients are multiples of 1
Alps0250I Starting search ...
CPX0000 Version identifier: 22.1.1.0 | 2022-11-28 | 9160aff4d
CPX0000 CPXPARAM_Preprocessing_Presolve 0
CPX0000
CPX0000 Iteration log . . .
CPX0000 Iteration: 1 Dual objective = -2.000000
terminate called after throwing an instance of 'std::bad_array_new_length'
what(): std::bad_array_new_length If anyone could help me with this, it would be more than appreciated. I am currently stuck at this state. Thank you, Henri. |
Beta Was this translation helpful? Give feedback.
-
Hi,
Apologies if I'm asking something that might have an evident solution due to my in-expertise.
My aim is to use MibS as a benchmark for a specialized algorithm I have in mind for a specific problem.
To make the comparison fair, I would prefer to code everything using C++.
I've been navigating in GitHub libraries including in COIN-OR, and I haven't been able to find a simple working example I can compile and run successfully that can write the instance, solve the problem and read the solution from MibS in memory using C++.
Here https://coin-or.github.io/MibS/ I found an example outlining how to do it, however I'm still struggling with even compiling a toy example.
The alternative solution I see seems much more time consuming: generate .MPS and auxiliary info .txt file, execute it, and extract the value of the variables from the output of the console.
Here is my question:
Many thanks!
Beta Was this translation helpful? Give feedback.
All reactions