3
$\begingroup$

I'm trying to validate my model, this is the relevant part of my code:

    cp_model.Maximize(LinearExpr::Sum(obj_final));

    SatHelper::ValidateModel(cp_model);
    //solve
    Model model;
    //
    // Sets a time limit of 10 seconds.

    SatParameters parameters;
    parameters.set_max_time_in_seconds(10.0);
    model.Add(NewSatParameters(parameters));

    // Solve.

    const CpSolverResponse response = SolveCpModel(cp_model.Build(), &model);
    LOG(INFO) << CpSolverResponseStats(response);

    if (response.status() == CpSolverStatus::FEASIBLE) {
        for (int j = 0; j < nbTasks; ++j)
        {
            LOG(INFO) << "  x = " << SolutionIntegerValue(response, starts[j]);
        }}

For some reason my model is invalid and I want to validate it to get detailed information about it. But I get this error:

 error: no matching function for call to ‘operations_research::sat::SatHelper::ValidateModel(operations_research::sat::Model&)’
     SatHelper::ValidateModel(model);

and suggests:

note: candidate: static std::__cxx11::string operations_research::sat::SatHelper::ValidateModel(const operations_research::sat::CpModelProto&)

So, what is a CpModelProto? I read the documentation but it is hard to understand. I've seen most of the c++ examples of or-tools and I haven't found any CpModelProto in the solving part. And finally, what can I do to validate my model and check where the problem is?

Additionally, if someone can give me a nice explanation of how to print/solve and setting parameters, it will be nice, because the examples use FLAGS and LOG and they are confusing.

Thanks!

$\endgroup$
4
$\begingroup$

CpModelProto is a protobuf representation of your model in ortools.

You create it by using the CpModelBuilder class (your cp_model), and calling its Build() method, the SolveCpModel function that you are using actually also takes a CpModelProto as its first argument.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks! it works, but its no printing anything. i used: std::cout << SatHelper::ValidateModel(cp_model.Build()) << std::endl; and just print coeffs: -1 on cmd. This is the info that the method drops? $\endgroup$ – Diego R. Troncoso Jan 23 at 15:38
  • $\begingroup$ If you parse C++ command line arguments using the Google gflags code, you can try with -vmodule=cp_model_checker=2. It should display more information $\endgroup$ – Laurent Perron Jan 23 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.