本文整理汇总了C++中SolutionPtr::get_problem方法的典型用法代码示例。如果您正苦于以下问题:C++ SolutionPtr::get_problem方法的具体用法?C++ SolutionPtr::get_problem怎么用?C++ SolutionPtr::get_problem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SolutionPtr
的用法示例。
在下文中一共展示了SolutionPtr::get_problem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cw_savings
/**
* Implementation of the Clarke and Wright savings algorithm
* This function modifies an existing solution by merging tours from the same depot if this results in a net
* cost reduction. The tours are merged in order of net reduction from highest to lowest. This is primarily
* used to initiate the solver with a sensible first guess.
*/
SolutionPtr cw_savings(SolutionPtr prevsol)
{
set<TourPtr> newsol;
for (auto depot : prevsol->get_problem()->get_depots())
{
vector<TourPtr> tours_vec = prevsol->tours_from_depot(depot);
set<TourPtr> tours(tours_vec.begin(), tours_vec.end());
while (true)
{
double reduction = -1;
TourPtr left, right;
for (auto t1 : tours)
for (auto t2 : tours)
{
if (t1 == t2)
continue;
double test_reduction = triangle(*t1->last(), *depot, *t2->first());
// Only accept this merge if it doesn't break the daily cap condition
if ( test_reduction > reduction
&& t1->duration() + t2->duration() - test_reduction <=
prevsol->get_problem()->get_daily_cap())
{
reduction = test_reduction;
left = t1;
right = t2;
}
}
if (reduction >= 0)
{
tours.erase(left);
tours.erase(right);
tours.insert(TourPtr(new Tour(*left, *right)));
}
else
break;
}
newsol.insert(tours.begin(), tours.end());
}
return SolutionPtr(new Solution(prevsol->get_problem(), newsol));
}