Skip to content
Snippets Groups Projects
Commit 9ef014fa authored by awenjb's avatar awenjb
Browse files

Data Checker

- data coherence checker added
- new folders
- new .cpp .h in modification (to do)
parent 8b7f287a
No related branches found
No related tags found
No related merge requests found
Showing
with 185 additions and 21 deletions
......@@ -24,8 +24,13 @@ add_executable(pdptw src/main.cpp
src/input/pdptw_data.cpp
src/input/time_window.cpp
src/input/json_parser.cpp
src/lns/route.cpp
src/lns/solution.cpp
src/lns/solution/route.cpp
src/lns/solution/solution.cpp
src/lns/modification/insert_pair.cpp
src/lns/modification/insert_route_with_pair.cpp
src/lns/modification/insert_route.cpp
src/lns/modification/remove_pair.cpp
src/lns/modification/remove_route.cpp
)
target_link_libraries(pdptw PRIVATE CLI11::CLI11 nlohmann_json::nlohmann_json spdlog::spdlog)
\ No newline at end of file
......@@ -4,6 +4,7 @@
#include <fstream>
#include <vector>
#include <nlohmann/json.hpp>
#include <spdlog/spdlog.h>
unsigned int PDPTWData::getSize()
......@@ -16,20 +17,32 @@ int PDPTWData::getCapacity()
return capacity;
}
std::vector<Location> const &PDPTWData::getLocations() const {
std::vector<Location> const &PDPTWData::getLocations() const
{
return locations;
}
Location const PDPTWData::getDepot() const{
Location const &PDPTWData::getDepot() const
{
return depot;
}
Location const &PDPTWData::getLocation(int id) const
{
return locations[id];
}
PDPTWData::PDPTWData(unsigned int size, int capacity, Location depot, std::vector<Location> location, Matrix distance_matrix)
: size(size), capacity(capacity), depot(depot), locations(std::move(location)), distance_matrix(std::move(distance_matrix)) {}
Matrix const &PDPTWData::getMatrix() const
{
return distanceMatrix;
}
PDPTWData::PDPTWData(unsigned int size, int capacity, Location depot, std::vector<Location> location, Matrix distanceMatrix)
: size(size), capacity(capacity), depot(depot), locations(std::move(location)), distanceMatrix(std::move(distanceMatrix)) {}
void PDPTWData::print() const {
void PDPTWData::print() const
{
std::cout << "Instance size: " << size << "\n";
std::cout << "Capacity: " << capacity << "\n";
std::cout << "Depot:\n";
......@@ -41,10 +54,100 @@ void PDPTWData::print() const {
}
std::cout << "Distance Matrix:\n";
for (const auto& row : distance_matrix) {
for (const auto& row : distanceMatrix) {
for (const auto& dist : row) {
std::cout << dist << " ";
}
std::cout << "\n";
}
}
\ No newline at end of file
}
void PDPTWData::checkData() const
{
bool errorFlag = checkMatrix();
errorFlag = checkLocation() || errorFlag;
//errorFlag = checkTimeWindow() || errorFlag;
if (errorFlag)
{
throw InputJsonException("failed to pass consistency checks");
}
}
bool PDPTWData::checkMatrix() const
{
// square matrix
for (const auto& row : getMatrix())
{
if (row.size() != size)
{
return true;
}
}
/*
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
for (int k = 0; k < size; k++)
{
if (getMatrix()[i][j] > getMatrix()[i][k] + getMatrix()[k][j])
{
return true;
}
}
}
}
*/
return false;
}
bool PDPTWData::checkLocation() const
{
// check if location id equals the position in the location vector
for (size_t i = 0; i < size-1; ++i) {
if (locations[i].getId() != static_cast<int>(i)+1) {
return true;
}
}
// check if pair of location are well made (type, id, demand, timeWindow)
for(const Location& loc : getLocations())
{
if (loc.getLocType() == LocType::PICKUP)
{
if ( (getLocations()[loc.getPair()-1].getLocType() != LocType::DELIVERY)
|| (loc.getDemand() != - getLocations()[loc.getPair()-1].getDemand())
|| (loc.getId() != getLocations()[loc.getPair()-1].getPair()) )
{
return true;
}
}
if (loc.getTimeWindow().getStart() > loc.getTimeWindow().getEnd())
{
return true;
}
}
return false;
}
InputJsonException::InputJsonException(std::string_view reason)
: reason(fmt::format("Input JSON file is incorrect : {}", reason))
{
spdlog::default_logger()->flush();
}
char const *InputJsonException::what() const noexcept
{
return reason.data();
}
......@@ -28,7 +28,7 @@ class PDPTWData
int capacity;
Location depot;
std::vector<Location> locations;
Matrix distance_matrix;
Matrix distanceMatrix;
public:
......@@ -41,18 +41,22 @@ public:
* Constructs an empty PDPTWData.
* @see parsing::parseJson
*/
PDPTWData(unsigned int size, int capacity, Location depot, std::vector<Location> requests, Matrix distance_matrix);
PDPTWData(unsigned int size, int capacity, Location depot, std::vector<Location> requests, Matrix distanceMatrix);
/**
* Checks some data coherence
*/
void checkData() const;
bool checkMatrix() const;
bool checkLocation() const;
std::vector<Location> const &getLocations() const;
Location const getDepot() const;
Location const &getLocation(int id) const;
Location const &getDepot() const;
Matrix const &getMatrix() const;
unsigned int getSize();
int getCapacity();
void print() const;
};
#include "route.h"
#include <iostream>
Route::Route(std::vector<int> route, int cost) : route(route), cost(cost) {}
......@@ -11,4 +12,13 @@ int Route::getCost() const
const std::vector<int>& Route::getRoute() const
{
return route;
}
\ No newline at end of file
}
void Route::print() const
{
for (const int& id : getRoute())
{
std::cout << id << ", ";
}
std::cout << "\n";
}
\ No newline at end of file
#pragma once
#include <vector>
#include "./../../input/time_window.h"
/**
* Represent a route for the PDPTW
......@@ -9,14 +10,21 @@ class Route
{
private:
std::vector<int> route;
int cost;
std::vector<int> route;
/* Stocké dans les contraintes
std::vector<TimeInteger> reach_time; // debut d'arrivee
std::vector<double> FTS; // forward time slack
std::vector<std::vector<double>> acc_cap; // inscreasing capacity allowed between two positions
*/
public:
Route(std::vector<int> route, int cost);
int getCost() const;
const std::vector<int>& getRoute() const;
void print() const;
};
\ No newline at end of file
#include "solution.h"
#include <iostream>
Solution::Solution(RequestBank bank, std::vector<Route> routes, int totalCost)
: bank(bank), routes(routes), totalCost(totalCost) {}
......@@ -16,4 +17,13 @@ const std::vector<Route> & Solution::getRoute() const
int Solution::getCost()
{
return totalCost;
}
void Solution::print() const
{
std::cout << "Cost :" << totalCost << "\n";
for (const Route& id : getRoute())
{
id.print();
}
}
\ No newline at end of file
......@@ -22,4 +22,5 @@ public:
const std::vector<Route> & getRoute() const;
int getCost();
void print() const;
};
\ No newline at end of file
......@@ -20,20 +20,21 @@ int main(int argc, char const *argv[])
{
/* code */
//std::string filepath = "/home/a24jacqb/Documents/Code/pdptw-main/data_in/test_inst.json";
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/n5000/bar-n5000-1.json";
std::cout << filepath << "\n";
PDPTWData data = parsing::parseJson(filepath);
data.checkData();
/* test */
TimeWindow tw = TimeWindow(3,4);
Location pos = Location(1, 1, 20, 3, tw, 4, 5, LocType::DEPOT);
// test parser
std::string filepath = "/home/a24jacqb/Documents/Code/pdptw-main/data_in/test_inst.json";
std::cout << filepath << "\n";
PDPTWData data = parsing::parseJson(filepath);
data.print();
return 0;
......
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