Skip to content
Snippets Groups Projects
Commit 88a1c34d authored by awenjb's avatar awenjb
Browse files

Add CleanEmptyRoute operator

parent 09e92279
No related branches found
No related tags found
No related merge requests found
......@@ -38,6 +38,7 @@ add_executable(pdptw src/mains/main.cpp
src/output/solution_checker.cpp
src/output/solution_exporter.cpp
src/lns/operators/sorting_strategy.cpp
src/lns/operators/destruction/clean_empty_route.cpp
src/lns/operators/destruction/random_destroy.cpp
src/lns/operators/destruction/string_removal.cpp
src/lns/operators/reconstruction/enumerate.cpp
......
......@@ -4,4 +4,4 @@ const int EXCLUSION_PENALTY = 100;
const int RANDOM_SEED = 100;
const int NUMBER_VEHICLE = 10;
\ No newline at end of file
const int NUMBER_VEHICLE = 20;
\ No newline at end of file
......@@ -80,7 +80,7 @@ output::LnsOutput lns::runLns(Solution const &initialSolution, OperatorSelector
Solution actualSolution = initialSolution;
LnsRuntimeData runtime = {actualSolution};
// temporary
// temporary fixed iteration
int iterationMax = 200;
while (iterationMax > 0)
{
......
......@@ -18,16 +18,19 @@ RemoveRoute::RemoveRoute(int routeIndex, std::vector<int> &&removedPairID)
void RemoveRoute::modifySolution(Solution &solution)
{
std::vector<Route> &routes = solution.getRoutes();
std::vector<int> const &locationIDs = routes.at(routeIndex).getRoute();
if (routes.at(routeIndex).getRoute().empty())
{
std::vector<int> const &locationIDs = routes.at(routeIndex).getRoute();
// update removedPairID
removedPairID.reserve(routes.at(routeIndex).getSize());
// update removedPairID
removedPairID.reserve(routes.at(routeIndex).getSize());
for (int id : locationIDs)
{
if (solution.getData().getLocation(id).getLocType() == LocType::PICKUP)
for (int id: locationIDs)
{
removedPairID.push_back(id);
if (solution.getData().getLocation(id).getLocType() == LocType::PICKUP)
{
removedPairID.push_back(id);
}
}
}
routes.erase(routes.begin() + routeIndex);
......@@ -46,4 +49,9 @@ int RemoveRoute::getRouteIndex() const
std::vector<int> const &RemoveRoute::getDeletedPairs() const
{
return removedPairID;
}
ModificationApplyVariant RemoveRoute::asApplyVariant() const
{
return *this;
}
\ No newline at end of file
......@@ -36,5 +36,8 @@ public:
*/
std::vector<int> const &getDeletedPairs() const override;
ModificationApplyVariant asApplyVariant() const override;
int getRouteIndex() const;
};
\ No newline at end of file
#include "clean_empty_route.h"
#include "lns/modification/route/remove_route.h"
CleanEmptyRoute::CleanEmptyRoute() {}
void CleanEmptyRoute::destroySolution(Solution &solution) const
{
for (int routeIndex = solution.getRoutes().size() - 1; routeIndex >= 0; --routeIndex)
{
if (solution.getRoute(routeIndex).getRoute().empty())
{
RemoveRoute remRoute = RemoveRoute(routeIndex);
solution.applyDestructSolution(remRoute);
}
}
}
\ No newline at end of file
#pragma once
#include "lns/operators/abstract_operator.h"
class CleanEmptyRoute : public DestructionOperator
{
public:
explicit CleanEmptyRoute();
/**
* This operator removes empty routes from the solution.
*/
void destroySolution(Solution &solution) const override;
};
......@@ -13,6 +13,7 @@
#include "lns/modification/route/insert_route.h"
#include "lns/modification/route/remove_route.h"
#include "lns/operators/abstract_operator.h"
#include "lns/operators/destruction/clean_empty_route.h"
#include "lns/operators/destruction/random_destroy.h"
#include "lns/operators/destruction/string_removal.h"
#include "lns/operators/reconstruction/enumerate.h"
......@@ -47,13 +48,17 @@ void simpleLNS(PDPTWData const &data, Solution &startingSolution)
ThresholdAcceptance acceptor(0.05);
// lns operators
SimpleOperatorSelector RandomDestroy_ShuffleBestInsert;
addAllReconstructor(RandomDestroy_ShuffleBestInsert);
RandomDestroy_ShuffleBestInsert.addDestructor(RandomDestroy(pairs));
SimpleOperatorSelector RandomDestroy_BestInsert;
addAllReconstructor(RandomDestroy_BestInsert);
RandomDestroy_BestInsert.addDestructor(RandomDestroy(pairs));
RandomDestroy_BestInsert.addDestructor(StringRemoval(10,10));
RandomDestroy_BestInsert.addDestructor(CleanEmptyRoute());
SimpleOperatorSelector largeSelector;
addAllReconstructor(largeSelector);
largeSelector.addDestructor(RandomDestroy(pairs));
largeSelector.addDestructor(RandomDestroy(manyPairs));
largeSelector.addDestructor(StringRemoval(10,10));
largeSelector.addDestructor(CleanEmptyRoute());
// SimpleOperatorSelector veryLargeSelector;
// addAllReconstructor(veryLargeSelector);
......@@ -68,8 +73,8 @@ void simpleLNS(PDPTWData const &data, Solution &startingSolution)
// lastSelector.addDestructor(RandomDestroy(manyPairs));
std::vector<SmallLargeOperatorSelector::StepSelector> selectors;
selectors.emplace_back(10, std::move(RandomDestroy_ShuffleBestInsert));
// selectors.emplace_back(100, std::move(largeSelector));
selectors.emplace_back(10, std::move(RandomDestroy_BestInsert));
selectors.emplace_back(50, std::move(largeSelector));
// selectors.emplace_back(2, std::move(veryLargeSelector));
// selectors.emplace_back(2, std::move(hugeSelector));
// selectors.emplace_back(2, std::move(lastSelector));
......@@ -78,7 +83,6 @@ void simpleLNS(PDPTWData const &data, Solution &startingSolution)
// run lns
output::LnsOutput result = lns::runLns(startingSolution, smallLargeSelector, acceptor);
result.getBestSolution().print();
std::cout << result.getNumberOfIteration() << " " << result.getTimeSpent() << std::endl;
}
......@@ -90,7 +94,7 @@ int main(int argc, char **argv)
///////////////////////////////////////////////////////////////////////
//std::string filepath = "/home/a24jacqb/Documents/Code/pdptw-main/data_in/n100/bar-n100-1.json";
std::string filepath = "/home/a24jacqb/Documents/Code/pdptw-main/data_in/pdp_100/lc101.json";
std::string filepath = "/home/a24jacqb/Documents/Code/pdptw-main/data_in/pdp_100/lrc201.json";
//std::string filepath = "/home/a24jacqb/Documents/Code/pdptw-main/data_in/Nantes_1.json";
//std::string filepath = "/home/a24jacqb/Documents/Code/pdptw-main/data_in/n5000/bar-n5000-1.json";
......@@ -103,6 +107,7 @@ int main(int argc, char **argv)
simpleLNS(data, startingSolution);
///
// std::cout << "===== TEST ===== \n";
// Solution testSolution = Solution::emptySolution(data);
......
......@@ -8,7 +8,12 @@
void addAllReconstructor(SimpleOperatorSelector &selector)
{
selector.addReconstructor(ListHeuristicCostOriented(SortingStrategyType::SHUFFLE, EnumerationType::ALL_INSERT_PAIR));
selector.addReconstructor(ListHeuristicCostOriented(SortingStrategyType::SHUFFLE, EnumerationType::ALL_INSERT_PAIR), 1);
selector.addReconstructor(ListHeuristicCostOriented(SortingStrategyType::FAR, EnumerationType::ALL_INSERT_PAIR), 1);
selector.addReconstructor(ListHeuristicCostOriented(SortingStrategyType::CLOSE, EnumerationType::ALL_INSERT_PAIR), 1);
selector.addReconstructor(ListHeuristicCostOriented(SortingStrategyType::TWWIDTH, EnumerationType::ALL_INSERT_PAIR), 1);
selector.addReconstructor(ListHeuristicCostOriented(SortingStrategyType::TWSTART, EnumerationType::ALL_INSERT_PAIR), 1);
selector.addReconstructor(ListHeuristicCostOriented(SortingStrategyType::TWEND, EnumerationType::ALL_INSERT_PAIR), 1);
}
int mainInterface(int argc, char **argv, std::function<void(PDPTWData &, Solution &)> function)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment