regroup code in routing module
This commit is contained in:
@@ -1135,6 +1135,25 @@ void RoutingModel::SetCommandLineOption(const string& name,
|
||||
}
|
||||
|
||||
|
||||
Assignment* RoutingModel::RestoreAssignment(const Assignment& solution) {
|
||||
QuietCloseModel();
|
||||
CHECK(assignment_ != NULL);
|
||||
assignment_->Copy(&solution);
|
||||
return DoRestoreAssignment();
|
||||
}
|
||||
|
||||
Assignment* RoutingModel::DoRestoreAssignment() {
|
||||
solver_->Solve(restore_assignment_, monitors_);
|
||||
if (collect_assignments_->solution_count() == 1) {
|
||||
status_ = ROUTING_SUCCESS;
|
||||
return collect_assignments_->solution(0);
|
||||
} else {
|
||||
status_ = ROUTING_FAIL;
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool RoutingModel::RoutesToAssignment(const std::vector<std::vector<NodeIndex> >& routes,
|
||||
bool ignore_inactive_nodes,
|
||||
bool close_routes,
|
||||
@@ -1264,17 +1283,10 @@ Assignment* RoutingModel::ReadAssignmentFromRoutes(
|
||||
if (!RoutesToAssignment(routes, ignore_inactive_nodes, true, assignment_)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
solver_->Solve(restore_assignment_, monitors_);
|
||||
// Solve() might still fail when checking constraints (most constraints are
|
||||
// not verified by RoutesToAssignment) or when filling in dimension variables.
|
||||
if (collect_assignments_->solution_count() >= 1) {
|
||||
status_ = ROUTING_SUCCESS;
|
||||
return collect_assignments_->solution(0);
|
||||
} else {
|
||||
status_ = ROUTING_FAIL;
|
||||
return NULL;
|
||||
}
|
||||
// DoRestoreAssignment() might still fail when checking constraints (most
|
||||
// constraints are not verified by RoutesToAssignment) or when filling in
|
||||
// dimension variables.
|
||||
return DoRestoreAssignment();
|
||||
}
|
||||
|
||||
void RoutingModel::AssignmentToRoutes(
|
||||
|
||||
@@ -338,6 +338,7 @@ class RoutingModel {
|
||||
void AddDisjunctionInternal(const std::vector<NodeIndex>& nodes, int64 penalty);
|
||||
void AddNoCycleConstraintInternal();
|
||||
void SetVehicleCostInternal(int vehicle, NodeEvaluator2* evaluator);
|
||||
Assignment* DoRestoreAssignment();
|
||||
// Returns NULL if no penalty cost, otherwise returns penalty variable.
|
||||
IntVar* CreateDisjunction(int disjunction);
|
||||
// Returns the first active node in nodes starting from index + 1.
|
||||
|
||||
Reference in New Issue
Block a user