Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/cpp_common/messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ class Messages {
#define ENTERING(x)
#define EXITING(x)
#else
#define ENTERING(x) x.log << "\n--> " << __PRETTY_FUNCTION__ << "\n"
#define EXITING(x) x.log << "\n<-- " << __PRETTY_FUNCTION__ << "\n"
#define ENTERING(x) x << "\n--> " << __PRETTY_FUNCTION__ << "\n"
#define EXITING(x) x << "\n<-- " << __PRETTY_FUNCTION__ << "\n"
#endif


Expand Down
10 changes: 7 additions & 3 deletions include/cpp_common/short_vehicle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <vector>
#include "c_types/typedefs.h"

namespace vrprouting {

/** @brief short_vehicle

@note C/C++/postgreSQL connecting structure for input
Expand All @@ -38,10 +40,12 @@ name | description
id | Vehicle's identifier
stops | Vehicle's stops
*/
struct Short_vehicle{
Id id; /** Vehicle's identifier */
std::vector<Id> stops; /** Stops */
class Short_vehicle{
public:
Id id; /** Vehicle's identifier */
std::vector<Id> stops; /** Stops */
};

} // namespace vrprouting

#endif // INCLUDE_CPP_COMMON_SHORT_VEHICLE_HPP_
4 changes: 2 additions & 2 deletions include/initialsol/simple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace simple {
class Initial_solution : public problem::Solution {
public:
Initial_solution() = delete;
Initial_solution(Initials_code, problem::PickDeliver*);
Initial_solution(Initials_code, problem::PickDeliver&);

void invariant() const;

Expand All @@ -55,7 +55,7 @@ class Initial_solution : public problem::Solution {
*/
void one_truck_all_orders();

void do_while_foo(int kind);
void do_while_foo(Initials_code);

void do_while_feasible(
problem::Vehicle_pickDeliver& truck,
Expand Down
2 changes: 1 addition & 1 deletion include/initialsol/tabu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Initial_solution : public problem::Solution {
Initial_solution() = delete;

/** @brief Creating a complete initial solution */
Initial_solution(TTimestamp, bool, problem::PickDeliver*);
Initial_solution(TTimestamp, bool, problem::PickDeliver&);

private:
using Solution::vehicles;
Expand Down
35 changes: 13 additions & 22 deletions include/problem/fleet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <vector>
#include <numeric>

#include "c_types/typedefs.h"
#include "cpp_common/short_vehicle.hpp"
#include "problem/vehicle_pickDeliver.hpp"

typedef struct Vehicle_t Vehicle_t;

namespace vrprouting {
class Messages;
class Short_vehicle;

namespace problem {
class Orders;
class Vehicle_node;

/*
* PVR = pnode
*/
class Fleet: protected std::vector<Vehicle_pickDeliver> {
public:
using std::vector<Vehicle_pickDeliver>::begin;
Expand All @@ -59,21 +53,17 @@ class Fleet: protected std::vector<Vehicle_pickDeliver> {

/** @brief Create a fleet based on the Vehicles of the problem */
Fleet(
Vehicle_t* vehicles , size_t size_vehicles,
const Orders& p_orders, std::vector<Vehicle_node>& p_nodes, size_t& node_id)
: m_used(),
m_unused() {
build_fleet(vehicles, size_vehicles, {}, p_orders, p_nodes, node_id);
}
Vehicle_t* , size_t,
const Orders&,
std::vector<Vehicle_node>&, size_t&);

/** @brief Create a fleet based on the Vehicles of the problem */
Fleet(Vehicle_t* vehicles , size_t size_vehicles,
const std::vector<Short_vehicle> &new_stops,
const Orders& p_orders, std::vector<Vehicle_node>& p_nodes, size_t& node_id)
: m_used(),
m_unused() {
build_fleet(vehicles, size_vehicles, new_stops, p_orders, p_nodes, node_id);
}
Fleet(
Vehicle_t*, size_t,
const std::vector<Short_vehicle>&,
const Orders&,
std::vector<Vehicle_node>&,
size_t&);

/** @brief creating a fleet without information is not allowed */
Fleet() = delete;
Expand Down Expand Up @@ -131,9 +121,10 @@ class Fleet: protected std::vector<Vehicle_pickDeliver> {

/** @brief build the fleet */
void build_fleet(
Vehicle_t*, size_t, const std::vector<Short_vehicle>&,
Vehicle_t*, size_t,
const std::vector<Short_vehicle>&,
const Orders&,
std::vector<Vehicle_node>& p_nodes, size_t& node_id);
std::vector<Vehicle_node>&, size_t&);

void invariant() const;

Expand Down
7 changes: 1 addition & 6 deletions include/problem/matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#pragma once

#include <map>
#include <utility>
#include <tuple>
#include <string>
#include <vector>

#include "cpp_common/base_matrix.hpp"
#include "cpp_common/identifiers.hpp"
#include "c_types/typedefs.h"

using Time_multipliers_t = struct Time_multipliers_t;

namespace vrprouting {
namespace problem {
Expand All @@ -50,9 +48,6 @@ class Matrix : public base::Base_Matrix {
/** brief constructor for matrix version with time dependant multipliers */
Matrix(Matrix_cell_t *, size_t, Time_multipliers_t*, size_t, const Identifiers<Id>&, Multiplier = 1.0);

/** brief constructor for euclidean version with time dependant multipliers */
Matrix(const std::map<std::pair<Coordinate, Coordinate>, Id>&, Time_multipliers_t*, size_t, Multiplier = 1.0);

/** brief constructor for matrix version default multipliers */
Matrix(Matrix_cell_t *, size_t, const Identifiers<Id>&, Multiplier = 1.0);

Expand Down
8 changes: 1 addition & 7 deletions include/problem/order.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,7 @@ class Order : public Identifier {
Order() = delete;

/** @brief initializing an order with the pick & drop information */
Order(Idx o_idx, Id o_id,
const Vehicle_node &p_pickup,
const Vehicle_node &p_delivery) :
Identifier(o_idx, o_id),
m_pickup(p_pickup),
m_delivery(p_delivery) {
}
Order(Idx, Id, const Vehicle_node&, const Vehicle_node&);

/** @name Accessors
* @{
Expand Down
48 changes: 4 additions & 44 deletions include/problem/orders.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
namespace vrprouting {
namespace problem {

class PickDeliver;

class Orders : public std::vector<Order> {
public:
using std::vector<Order>::size;
Orders() = default;

// todo remove template its problem::PickDeliver
template <typename PTR>
Orders(Orders_t* p_orders, size_t p_size_orders, const PTR problem_ptr) {
Tw_node::m_time_matrix_ptr = &problem_ptr->time_matrix();
build_orders(p_orders, p_size_orders, problem_ptr);
}
Orders(Orders_t* , size_t, PickDeliver&);

/** @brief find the best order -> @b this */
size_t find_best_I(const Identifiers<size_t> &within_this_set) const;
Expand All @@ -80,8 +77,7 @@ class Orders : public std::vector<Order> {
}

private:
template <typename PTR>
void build_orders(Orders_t *, size_t, const PTR problem_ptr);
void build_orders(Orders_t *, size_t, PickDeliver&);

/** @brief add in an order */
void add_order(const Orders_t &order,
Expand All @@ -91,42 +87,6 @@ class Orders : public std::vector<Order> {
}
};

/**
@param [in] orders
@param [in] size_orders
@param [in] problem_ptr pointer to problem to get some needed information
*/
template <typename PTR>
void
Orders::build_orders(Orders_t *orders, size_t size_orders, const PTR problem_ptr) {
/**
* - Sort orders: ASC pick_open_t, deliver_close_t, id
*/
std::sort(orders, orders + size_orders,
[] (const Orders_t &lhs, const Orders_t &rhs) {
if (lhs.pick_open_t == rhs.pick_open_t) {
if (lhs.deliver_close_t == rhs.deliver_close_t) {
return lhs.id < rhs.id;
} else {
return lhs.deliver_close_t < rhs.deliver_close_t;
}
} else {
return lhs.pick_open_t < rhs.pick_open_t;
}
});

for (size_t i = 0; i < size_orders; ++i) {
auto order = orders[i];
Vehicle_node pick({problem_ptr->node_id()++, order, NodeType::kPickup});
Vehicle_node drop({problem_ptr->node_id()++, order, NodeType::kDelivery});

problem_ptr->add_node(pick);
problem_ptr->add_node(drop);

this->emplace_back(Order{size(), order.id, pick, drop});
}
}

} // namespace problem
} // namespace vrprouting

Expand Down
53 changes: 16 additions & 37 deletions include/problem/pickDeliver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,68 +29,47 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#define INCLUDE_PROBLEM_PICKDELIVER_HPP_
#pragma once



#include <vector>
#include <utility>
#include "c_types/compatibleVehicles_rt.h"
#include "c_types/solution_rt.h"
#include "cpp_common/orders_t.hpp"
#include "cpp_common/vehicle_t.hpp"

#include "cpp_common/messages.hpp"
#include "problem/vehicle_node.hpp"
#include "problem/orders.hpp"
#include "problem/fleet.hpp"
#include "problem/matrix.hpp"

using CompatibleVehicles_rt = struct CompatibleVehicles_rt;
using Orders_t = struct Orders_t;
using Vehicle_t = struct Vehicle_t;

namespace vrprouting {

class Short_vehicle;

namespace problem {

class Matrix;
class Vehicle_node;


/** @brief the pick deliver problem */
class PickDeliver {
public:
/** @brief General Constructor */
PickDeliver(
Orders_t* p_orders, size_t p_orders_size,
Vehicle_t* p_vehicles, size_t p_vehicles_size,
const Matrix &p_cost_matrix) :
m_cost_matrix(p_cost_matrix),
m_orders(p_orders, p_orders_size, this),
m_trucks(p_vehicles, p_vehicles_size, m_orders, m_nodes, m_node_id) {
if (!msg.get_error().empty()) return;
m_trucks.clean();
m_orders.set_compatibles();
m_trucks.set_compatibles(m_orders);
}
const Matrix &p_cost_matrix);

/** @brief Override stops constructor */
PickDeliver(
Orders_t* p_orders, size_t p_orders_size,
Vehicle_t* p_vehicles, size_t p_vehicles_size,
std::vector<Short_vehicle> new_stops,
const Matrix &p_cost_matrix) :
m_cost_matrix(p_cost_matrix),
m_orders(p_orders, p_orders_size, this),
m_trucks(p_vehicles, p_vehicles_size, new_stops, m_orders, m_nodes, m_node_id) {
if (!msg.get_error().empty()) return;
m_trucks.clean();
m_orders.set_compatibles();
m_trucks.set_compatibles(m_orders);
}
const Matrix &p_cost_matrix);

virtual ~PickDeliver() = default;

/** @brief get the vehicles compatibility results as C++ container */
std::vector<CompatibleVehicles_rt> get_pg_compatibleVehicles() const {
std::vector<CompatibleVehicles_rt> result;
for (const auto& v : m_trucks) {
if (v.is_phony()) continue;
for (const auto o : v.feasible_orders()) {
result.push_back({m_orders[o].id(), v.id()});
}
}
return result;
}
std::vector<CompatibleVehicles_rt> get_pg_compatibleVehicles() const;

const Orders& orders() {return m_orders;}
const Fleet& vehicles() {return m_trucks;}
Expand All @@ -100,7 +79,7 @@ class PickDeliver {

/** the cost matrix */
const Matrix& m_cost_matrix;
const Matrix& time_matrix() {return m_cost_matrix;}
const Matrix& time_matrix() const {return m_cost_matrix;}
size_t& node_id() {return m_node_id;}


Expand Down
Loading