Error 10003 Invalid arguments in callback function
ユーザーの入力を待っています。Hello,
I am trying to get the values of the GRBVariables inside the callback function of a user-defined class inherited from GRBCallback. However when i run getSolution() or setSolution the error 10003 invalid arguments arise. May you help me find out what am i doing wrong? . I paste the code down below.
GRBVar* init_arrival(GRBModel& model,vec_pair time_window)
{
GRBVar * arrival_time = new GRBVar[customers];
arrival_time[0] = model.addVar(0.0, GRB_INFINITY, 0.0, GRB_CONTINUOUS, "arrive at depot ");
for (int i = 1; i < customers; i++)
{
arrival_time[i] = model.addVar(0.0, time_window[i].second, 0.0, GRB_CONTINUOUS, "arrive at customer " + std::to_string(i));
}
return arrival_time;
}
GRBVar* init_depart(GRBModel& model,vec_pair time_window,float_vec service)
{
GRBVar* depart_time = new GRBVar [customers];
depart_time[0] = model.addVar(0.0, 0.0, 0.0, GRB_CONTINUOUS, "depart from depot");
for (int i = 1; i < customers; i++)
{
depart_time[i] = model.addVar(0.0, time_window[i].second + service[i], 0.0, GRB_CONTINUOUS, "depart from customer " + std::to_string(i));
}
return depart_time;
}
void Callbck::callback()
{
try
{
if (where == GRB_CB_MIPNODE)
{
double* arrival = new double[customers];
double* depart = new double[customers];
arrival = getSolution(arrival_time,customers); // Here is where the error occures
/*for (int i = 1; i < customers; i++)
{
if (arrival[i] < time_window[i].first)
{
setSolution(arrival_time[i], time_window[i].first);
}
}
setSolution(depart_time[0], 0.0);
for (int i = 1; i < customers; i++)
{
depart[i] = (arrival[i] > time_window[i].first) ? arrival[i] : time_window[i].first;
depart[i] += service_time[i];
setSolution(depart_time[i], depart[i]);
}
delete[] arrival;
delete[] depart;
*/
}
}
catch (GRBException e)
{
std::cout << "Error number: " << e.getErrorCode() << std::endl;
std::cout << e.getMessage() << std::endl;
}
catch (...)
{
std::cout << "Error during callback " << std::endl;
}
};
Best Regards,
-
Hi Giorgos,
Your code is not a reproducible example, which makes it hard to debug, but looking through our source code to see where this error is thrown it would suggest that the arrival_time argument ingetSolution(arrival_time,customers)
is NULL. This is just a guess but perhaps you should make sure that the method init_arrival is run and that the return value is assigned to the arrival_time pointer. In any case I hope this gives you some clues as to how to fix your issue.
- Riley
0
サインインしてコメントを残してください。
コメント
1件のコメント