Skip to content

Commit

Permalink
Merge pull request #16 from licit-lab/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
becarie authored Jul 28, 2023
2 parents 0081f61 + e2e414f commit 7264148
Show file tree
Hide file tree
Showing 16 changed files with 452 additions and 56 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,6 @@ doc/_dvlpt/
#OSX
.DS_Store

doc/tutorials/results/*
doc/tutorials/results/*
.vscode/launch.json
cpp/examples.zip
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"iosfwd": "cpp"
}
}
6 changes: 3 additions & 3 deletions conda/recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ outputs:
- {{ compiler('cxx') }}
- make
- cmake
- python=3.8
- python=3.10
host:
- python=3.8
- python=3.10
- hipoplib
- pybind11
run:
- python=3.8
- python=3.10
- hipoplib
- numpy
- matplotlib
Expand Down
19 changes: 19 additions & 0 deletions cpp/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.0)

project(HipopExample)

find_package(OpenMP REQUIRED)
find_package(Hipop REQUIRED)

include_directories("../include")
link_directories("../build/src")

set( SRCS ParallelKShortestPath.cpp)

add_executable(HipopExample ${SRCS})

set_property(TARGET HipopExample PROPERTY CXX_STANDARD 17)

target_link_libraries(HipopExample hipoplib)


37 changes: 37 additions & 0 deletions cpp/examples/ParallelKShortestPath.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <hipop/graph.h>
#include <hipop/shortest_path.h>

int main()
{
hipop::OrientedGraph G;

G.AddNode("0", 0, 0);
G.AddNode("1", 1, 1);
G.AddNode("2", 1, -1);
G.AddNode("3", 2, 0);
G.AddNode("4", 2, 1);

G.AddLink("0_1", "0", "1", 1, {{"PersonalVehicle", {{"time", 14}}}}, "CAR");
G.AddLink("1_3", "1", "3", 1, {{"PersonalVehicle", {{"time", 12}}}}, "CAR");
G.AddLink("0_2", "0", "2", 1, {{"PersonalVehicle", {{"time", 12}}}}, "CAR");
G.AddLink("2_3", "2", "3", 1, {{"PersonalVehicle", {{"time", 12}}}}, "CAR");
G.AddLink("0_3", "0", "3", 1, {{"PersonalVehicle", {{"time", 12}}}}, "CAR");
G.AddLink("0_4", "0", "4", 11, {{"PersonalVehicle", {{"time", 14}}}}, "CAR");
G.AddLink("4_3", "4", "3", 11, {{"PersonalVehicle", {{"time", 12}}}}, "CAR");



std::vector<std::string> origins = {"0", "0", "0", "0"};
std::vector<std::string> destinations = {"3", "3", "3", "3"};
std::vector<std::unordered_map<std::string, std:: string> > vecMapLabelCosts = {
{{"CAR", "PersonalVehicle"}},
{{"CAR", "PersonalVehicle"}},
{{"CAR", "PersonalVehicle"}},
{{"CAR", "PersonalVehicle"}}
};

//auto paths = hipop::parallelKShortestPath(G, origins, destinations, "time", vecMapLabelCosts, {}, 0, 10, 4, 4);
auto paths = hipop::parallelDijkstra(G, origins, destinations, vecMapLabelCosts, "time", 4, {});

return EXIT_SUCCESS;
}
2 changes: 2 additions & 0 deletions cpp/include/hipop/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ namespace hipop
void AddLink(std::string _id, std::string _up, std::string _down, double length, mapcosts _costs, std::string label = "");
void AddLink(Link* l);
void UpdateLinkCosts(std::string lid, mapcosts _costs);
void UpdateCosts(std::unordered_map<std::string, mapcosts> maplinkcosts);
double getLength(std::string _up, std::string _down);

void ShowNodes();
void ShowLinks();
Expand Down
20 changes: 18 additions & 2 deletions cpp/include/hipop/shortest_path.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ namespace hipop
{
double computePathLength(OrientedGraph &G, const std::vector<std::string> &path);

double computePathCost(OrientedGraph &G, const std::vector<std::string> &path, std::string cost, const std::unordered_map<std::string, std::string> mapLabelCost);

std::vector<std::vector<double>> computePathsCosts(OrientedGraph &G,
const std::vector<std::vector<std::vector<std::string>>> &paths,
const std::string &cost,
const std::unordered_map<std::string, std::string> mapLabelCost,
int threadNumber);

pathCost dijkstra(
const OrientedGraph &G,
const std::string &origin,
Expand Down Expand Up @@ -77,6 +85,14 @@ namespace hipop
int kPath,
int threadNumber);

} // namespace hipop

std::vector<pathCost> parallelIntermodalDijkstra(
const OrientedGraph &G,
std::vector<std::string> origins,
std::vector<std::string> destinations,
std::vector<std::unordered_map<std::string, std::string> > vecMapLabelCosts,
std::string cost,
int threadNumber,
std::pair<std::unordered_set<std::string>, std::unordered_set<std::string>> pairMandatoryLabels,
std::vector<setstring> vecAvailableLabels = {});

} // namespace hipop
25 changes: 24 additions & 1 deletion cpp/src/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ namespace hipop
mlinks[lid]->updateCosts(_costs);
}

/**
* @brief Update a list of link costs
*
* @param maplinkcosts The map of the links/costs to update
*/
void OrientedGraph::UpdateCosts(std::unordered_map<std::string, mapcosts> maplinkcosts)
{
for (auto it = maplinkcosts.begin(); it!= maplinkcosts.end(); it++)
{
UpdateLinkCosts(it->first, it->second);
}
}

/**
* @brief Print the Nodes informations
*
Expand All @@ -119,6 +132,17 @@ namespace hipop
}
}

/**
* @brief Get the length of a link
*
* @param _up the upstream node of the link
* @param _down the downstream node of the link
* @return double the length of the link
*/
double OrientedGraph::getLength(std::string _up, std::string _down)
{
return mnodes[_up]->madj[_down]->mlength;
}

/**
* @brief Make a deep copy of an OrientedGraph
Expand Down Expand Up @@ -197,7 +221,6 @@ namespace hipop

return newGraph;
}

} // namespace hipop


Loading

0 comments on commit 7264148

Please sign in to comment.