Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 5 additions & 22 deletions include/cpp_common/base_matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

********************************************************************PGR-GNU*/

/*! @file */

#ifndef INCLUDE_CPP_COMMON_BASE_MATRIX_HPP_
#define INCLUDE_CPP_COMMON_BASE_MATRIX_HPP_
#pragma once

#include <iosfwd>
#include <vector>
#include <map>
#include <utility>
#include <cstdint>

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

#include "structures/generic/matrix.h"

typedef struct Matrix_cell_t Matrix_cell_t;

namespace vrprouting {
Expand All @@ -63,19 +57,16 @@ class Base_Matrix {
/** @brief Constructs an emtpy matrix */
Base_Matrix() = default;
/** @brief Constructs a matrix for only specific identifiers */
Base_Matrix(Matrix_cell_t *, size_t, const Identifiers<Id>&, Multiplier);
Base_Matrix(Vroom_matrix_t *, size_t, const Identifiers<Id> &, double);
explicit Base_Matrix(const std::map<std::pair<Coordinate, Coordinate>, Id> &, Multiplier);
Base_Matrix(Matrix_cell_t*, size_t, const Identifiers<Id>&, Multiplier);
/** @brief Constructs a matrix for the euclidean */
Base_Matrix(const std::map<std::pair<Coordinate, Coordinate>, Id>&, Multiplier);

/** @name status of the matrix
* @{
*/
/** @brief does the matrix values not given by the user? */
bool has_no_infinity() const;

vroom::Matrix<vroom::Duration> get_vroom_duration_matrix() const;
vroom::Matrix<vroom::Cost> get_vroom_cost_matrix() const;

/** @brief does the matrix obeys the triangle inequality? */
bool obeys_triangle_inequality() const;
size_t fix_triangle_inequality(size_t depth = 0);
Expand All @@ -89,8 +80,6 @@ class Base_Matrix {
*/
size_t size() const {return m_ids.size();}

/** @brief is the matrix symetric? */
bool is_symmetric() const;

/** @}*/

Expand All @@ -108,11 +97,11 @@ class Base_Matrix {
/** @brief original id -> idx */
Idx get_index(Id) const;

/** @brief original id -> idx */
/** @brief idx -> original id */
Id get_original_id(Idx) const;

private:
/** @brief Traverses the matrix information to set the ids of the nodes */
/** @brief set the ids of the nodes */
void set_ids(const std::vector<Matrix_cell_t> &);

/** DATA **/
Expand All @@ -124,12 +113,6 @@ class Base_Matrix {
* m_time_matrix[i][j] i and j are index from the ids
*/
std::vector<std::vector<TInterval>> m_time_matrix;

/** @brief the cost matrix for vroom
*
* m_cost_matrix[i][j] i and j are index from the ids
*/
std::vector<std::vector<TravelCost>> m_cost_matrix;
};

} // namespace base
Expand Down
96 changes: 96 additions & 0 deletions include/cpp_common/vroom_matrix.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*PGR-GNU*****************************************************************

FILE: vroom_matrix.hpp

Copyright (c) 2024 pgRouting developers
Mail: project@pgrouting.org

------

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

********************************************************************PGR-GNU*/

/*! @file */

#ifndef INCLUDE_CPP_COMMON_VROOM_MATRIX_HPP_
#define INCLUDE_CPP_COMMON_VROOM_MATRIX_HPP_
#pragma once

#include <structures/generic/matrix.h>

#include <iosfwd>
#include <vector>
#include <map>
#include <utility>
#include <cstdint>

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


typedef struct Matrix_cell_t Matrix_cell_t;

namespace vrprouting {
namespace vroom {

/** @brief N x N matrix
*
* - The internal data interpretation is done by the user of this class
* - Once created do not modifiy
*/
class Matrix {
public:
/** @brief Constructs an emtpy matrix */
Matrix() = default;
Matrix(Vroom_matrix_t *, size_t, const Identifiers<Id> &, double);

::vroom::Matrix<::vroom::Duration> get_vroom_duration_matrix() const;
::vroom::Matrix<::vroom::Cost> get_vroom_cost_matrix() const;

/** @brief the size of the matrix */
size_t size() const {return m_ids.size();}

/** @brief original id -> idx */
Idx get_index(Id) const;

/** @brief original id -> idx */
Id get_original_id(Idx) const;

/** @brief has identifier */
bool has_id(Id) const;

private:
typedef std::vector<std::vector<std::pair<TInterval, TravelCost>>> VMatrix;

/** @brief does the matrix values not given by the user? */
bool has_infinity(const VMatrix&) const;
void set_vroom_duration_matrix(const VMatrix&);
void set_vroom_cost_matrix(const VMatrix&);

/** DATA **/
/** ordered list of user identifiers */
std::vector<Id> m_ids;

/** @brief the dureation matrix for vroom */
::vroom::Matrix<::vroom::Duration> m_dmatrix;
/** @brief the dureation matrix for vroom */
::vroom::Matrix<::vroom::Cost> m_cmatrix;
};

} // namespace vroom
} // namespace vrprouting

#endif // INCLUDE_CPP_COMMON_VROOM_MATRIX_HPP_
36 changes: 18 additions & 18 deletions include/vroom/vroom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <vector>

#include "c_types/typedefs.h"
#include "cpp_common/base_matrix.hpp"
#include "cpp_common/vroom_matrix.hpp"
#include "cpp_common/messages.hpp"

using Vroom_rt = struct Vroom_rt;
Expand Down Expand Up @@ -70,40 +70,40 @@ class Vroom : public vrprouting::Messages {
void add_vehicles(const Vroom_vehicle_t*, size_t, const Vroom_break_t*, size_t, const Vroom_time_window_t*, size_t);

/** @brief sets m_matrix */
void add_matrix(const vrprouting::base::Base_Matrix&);
void add_matrix(const vrprouting::vroom::Matrix&);

/** @brief solves the vroom problem */
std::vector<Vroom_rt> solve(int32_t, int32_t, int32_t);

private:
std::vector<vroom::TimeWindow> get_vroom_time_windows(const std::vector<Vroom_time_window_t>&) const;
vroom::Amount get_vroom_amounts(const std::vector<Amount>&) const;
vroom::Amount get_vroom_amounts(const Amount *amounts, size_t count) const;
vroom::Skills get_vroom_skills(const Skill*, size_t) const;
vroom::Job get_vroom_job(
std::vector<::vroom::TimeWindow> get_vroom_time_windows(const std::vector<Vroom_time_window_t>&) const;
::vroom::Amount get_vroom_amounts(const std::vector<Amount>&) const;
::vroom::Amount get_vroom_amounts(const Amount *amounts, size_t count) const;
::vroom::Skills get_vroom_skills(const Skill*, size_t) const;
::vroom::Job get_vroom_job(
const Vroom_job_t&,
const std::vector<Vroom_time_window_t>&) const;
std::pair<vroom::Job, vroom::Job> get_vroom_shipment(
std::pair<::vroom::Job, ::vroom::Job> get_vroom_shipment(
const Vroom_shipment_t&,
const std::vector<Vroom_time_window_t>&,
const std::vector<Vroom_time_window_t>&) const;
std::vector<vroom::Break> get_vroom_breaks(
std::vector<::vroom::Break> get_vroom_breaks(
const std::vector<Vroom_break_t>&,
const std::vector<Vroom_time_window_t>&) const;
vroom::Vehicle get_vroom_vehicle(
::vroom::Vehicle get_vroom_vehicle(
const Vroom_vehicle_t&,
const std::vector<Vroom_break_t>&,
const std::vector<Vroom_time_window_t>&) const;
void get_amount(vroom::Amount, Amount**);
StepType get_job_step_type(vroom::JOB_TYPE);
StepType get_step_type(vroom::Step);
std::vector<Vroom_rt> get_results(vroom::Solution);
void get_amount(::vroom::Amount, Amount**);
StepType get_job_step_type(::vroom::JOB_TYPE);
StepType get_step_type(::vroom::Step);
std::vector<Vroom_rt> get_results(::vroom::Solution);

private:
std::vector<vroom::Job> m_jobs;
std::vector<std::pair<vroom::Job, vroom::Job>> m_shipments;
std::vector<vroom::Vehicle> m_vehicles;
vrprouting::base::Base_Matrix m_matrix;
std::vector<::vroom::Job> m_jobs;
std::vector<std::pair<::vroom::Job, ::vroom::Job>> m_shipments;
std::vector<::vroom::Vehicle> m_vehicles;
vrprouting::vroom::Matrix m_matrix;
};

} // namespace problem
Expand Down
1 change: 1 addition & 0 deletions src/cpp_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ ADD_LIBRARY(cpp_common OBJECT
assert.cpp
alloc.cpp
get_check_data.c
vroom_matrix.cpp
)
Loading