how do I change variable type with c++ API?
AnsweredHi, everyone, I'm practice with the diet_c++.cpp, I want to change the variable type, I modified the API like below, but the results show it doesn't work, could anyone tell me what mistake I was take?
Thanks.
// Create decision variables for the nutrition information,
// which we limit via bounds
nutrition = model.addVars(minNutrition, maxNutrition, nullptr, 0, Categories, nCategories);
//nutrition->set(GRB_CharAttr_VType, GRB_INTEGER); //修改变量类型为整型变量
for (size_t p = 0; p < nCategories; ++p)
{
nutrition[p].set(GRB_CharAttr_VType, GRB_INTEGER);
}
// Create decision variables for the foods to buy
buy = model.addVars(nullptr, nullptr, cost, 0, Foods, nFoods);
//buy->set(GRB_CharAttr_VType, GRB_INTEGER);
for (size_t p = 0; p < nCategories; ++p)
{
buy[p].set(GRB_CharAttr_VType, GRB_INTEGER);
}
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Hi Dapei,
Except for
for (size_t p = 0; p < nCategories; ++p)
{
buy[p].set(GRB_CharAttr_VType, GRB_INTEGER);
}which should read
for(size_t p = 0; p < nFoods /* there are only nFoods "buy" variables */; ++p)
{
buy[p].set(GRB_CharAttr_VType, GRB_INTEGER);
}the code looks fine. Why do you think that it does not work?
Best regards,
Jaromił0 -
oooooooooh! I make a foolish mistake, I'm so stupid.
Mr Najman, Thank you!
0
Post is closed for comments.
Comments
3 comments