Skip to content
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

C++ Hello World - Segmentation Fault #134

Open
hlefebvr opened this issue Feb 1, 2024 · 0 comments
Open

C++ Hello World - Segmentation Fault #134

hlefebvr opened this issue Feb 1, 2024 · 0 comments

Comments

@hlefebvr
Copy link

hlefebvr commented Feb 1, 2024

Hello,

I am trying to build a minimal example for using MibS with C++.

Context

I am trying to model the following problem using the C++ API:

 min  -x − 7y
 s.t.   -3x + 2y ≤ 12
             x + 2y ≤ 20
             x ≤ 10
             y ∈ arg min {z : 2x - z ≤ 7,
                              -2x + 4z ≤ 16,
                              z ≤ 5}

Setting

  • MibS 1.2 as built using coinbrew and linked with Cplex - though the problem I am facing seems indifferent to CPLEX.
  • Ubuntu 22.04 LTS
  • CMake as build system
  • C++17

My Attempt

So far, I have tried with the following code.

    std::unique_ptr<OsiSolverInterface> solver(new OsiCpxSolverInterface());

    MibSModel model;
    model.setSolver(solver.get());

   // AUXILIARY DATA
    std::vector<int> upper_level_variables_indices = { 0,  };
    std::vector<int> lower_level_variables_indices = { 1,  };
    std::vector<int> upper_level_constraints_indices = { 0, 1,  };
    std::vector<int> lower_level_constraints_indices = { 2, 3,  };
    std::vector<double> lower_level_objective_coefficients = { 1,  };

    model.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
    );

   // PROBLEM DATA

    std::vector<double> variable_lower_bounds = { 0, 0,  };
    std::vector<double> variable_upper_bounds = { 10, 5,  };
    std::vector<char> variable_types = { 'I', 'I',  };
    std::vector<double> constraint_lower_bounds = { -1e+20, -1e+20, -1e+20, -1e+20,  };
    std::vector<double> constraint_upper_bounds = { 12, 20, 7, 16,  };
    std::vector<char> constraint_types = { 'L', 'L', 'L', 'L',  };
    std::vector<double> objective = { -1, -7,  };

    CoinPackedMatrix matrix(false, 0, 2);

    CoinPackedVector row1;
    row1.insert(0, -3);
    row1.insert(1, 2);
    matrix.appendRow(row1);

    CoinPackedVector row2;
    row2.insert(0, 1);
    row2.insert(1, 2);
    matrix.appendRow(row2);

    CoinPackedVector row3;
    row3.insert(0, 2);
    row3.insert(1, -1);
    matrix.appendRow(row3);

    CoinPackedVector row4;
    row4.insert(0, -2);
    row4.insert(1, 4);
    matrix.appendRow(row4);

    model.loadProblemData(
            matrix,
            variable_lower_bounds.data(),
            variable_upper_bounds.data(),
            objective.data(),
            constraint_lower_bounds.data(),
            constraint_upper_bounds.data(),
            variable_types.data(),
            1.,
            1e+20,
            constraint_types.data()
    );

Quesitons and Problems

  • I get a Segmentation Fault when running this code. This happens in the call of loadProblemData and, in particular, seems to be in setUpperRowData.
  • What does the arguments structRowXX relate to ?

Thank you,

Henri.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant