Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Recreated repository to get rid of binaries files that accidently got…

… committed and which needlessly increase size of the repository.
  • Loading branch information...
commit 5eb82b12f3cd2aacbef610580c6c835b6d36398d 0 parents
@dennisferron authored
66 .gitignore
@@ -0,0 +1,66 @@
+# Ignore binaries
+Project/bin/Debug/*
+Project/bin/Release/*
+
+#Ignore profile/trace files
+gmon.out
+*.gcda
+*.gcno
+
+#Ignore bullsh*t files codeblocks creates that show up as changed every time
+#and clutter your git repo even though nothing important is really new in them
+*.layout
+*.depend
+*.cbtemp
+
+#Ignore callgrind profiles
+callgrind*
+callgrind.*
+callgrind.out.*.*
+
+# Ignore generated dll files
+*.dll
+*.so
+*.so.*
+*.so.*.*
+*.so.*.*.*
+
+# Ignore generated program binaries.
+*.exe
+
+# Ignore text editor backup copies
+*~
+
+# Ignore intermediate build files.
+*.o.d
+*.o
+*.lo
+*.a
+*.la
+*.lai
+*.lib
+autom4te.cache/*
+*.cpp~
+*.hpp~
+*.Po
+*.Plo
+*.Tpo
+.deps/*
+*/.deps/*
+
+# Ignore temporary build dirs
+.libs/*
+_libs/*
+
+# Ignore logs generated by the program
+*.log
+log/*
+
+# Ignore doxygen output (which can be quite sizeable).
+doxygen/*
+*.html
+*.tex
+*.eps
+*.xml
+
+
18 Demo/main.cpp
@@ -0,0 +1,18 @@
+#include <iostream>
+
+using namespace std;
+
+int do_test();
+
+namespace Plandipitous {
+ void do_test_2();
+}
+
+int main()
+{
+ //do_test();
+ Plandipitous::do_test_2();
+ std::cout << "Press enter..." << std::endl;
+ std::cin.ignore( 99, '\n' );
+ return 0;
+}
1  Include/Plandipitous.hpp
@@ -0,0 +1 @@
+
47 Project/Plandipitous-Demo-Linux.cbp
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<CodeBlocks_project_file>
+ <FileVersion major="1" minor="6" />
+ <Project>
+ <Option title="Plandipitous-Demo" />
+ <Option pch_mode="2" />
+ <Option compiler="gcc" />
+ <Build>
+ <Target title="Debug">
+ <Option output="bin/Debug/Plandipitous-Demo" prefix_auto="1" extension_auto="1" />
+ <Option object_output="obj/Debug/" />
+ <Option type="1" />
+ <Option compiler="gcc" />
+ <Compiler>
+ <Add option="-g" />
+ </Compiler>
+ </Target>
+ <Target title="Release">
+ <Option output="bin/Release/Plandipitous-Demo" prefix_auto="1" extension_auto="1" />
+ <Option object_output="obj/Release/" />
+ <Option type="1" />
+ <Option compiler="gcc" />
+ <Compiler>
+ <Add option="-O2" />
+ </Compiler>
+ <Linker>
+ <Add option="-s" />
+ </Linker>
+ </Target>
+ </Build>
+ <Compiler>
+ <Add option="-Wall" />
+ <Add option="-fexceptions" />
+ <Add directory="../Include" />
+ <Add directory="../../boost" />
+ </Compiler>
+ <Linker>
+ <Add library="libPlandipitous-Linux.a" />
+ <Add directory="../Project" />
+ </Linker>
+ <Unit filename="../Demo/main.cpp" />
+ <Extensions>
+ <code_completion />
+ <debugger />
+ </Extensions>
+ </Project>
+</CodeBlocks_project_file>
47 Project/Plandipitous-Demo-Windows.cbp
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<CodeBlocks_project_file>
+ <FileVersion major="1" minor="6" />
+ <Project>
+ <Option title="Plandipitous-Demo" />
+ <Option pch_mode="2" />
+ <Option compiler="gcc" />
+ <Build>
+ <Target title="Debug">
+ <Option output="bin\Debug\Plandipitous-Demo" prefix_auto="1" extension_auto="1" />
+ <Option object_output="obj\Debug\" />
+ <Option type="1" />
+ <Option compiler="gcc" />
+ <Compiler>
+ <Add option="-g" />
+ </Compiler>
+ </Target>
+ <Target title="Release">
+ <Option output="bin\Release\Plandipitous-Demo" prefix_auto="1" extension_auto="1" />
+ <Option object_output="obj\Release\" />
+ <Option type="1" />
+ <Option compiler="gcc" />
+ <Compiler>
+ <Add option="-O2" />
+ </Compiler>
+ <Linker>
+ <Add option="-s" />
+ </Linker>
+ </Target>
+ </Build>
+ <Compiler>
+ <Add option="-Wall" />
+ <Add option="-fexceptions" />
+ <Add directory="..\..\boost" />
+ <Add directory="..\Include" />
+ </Compiler>
+ <Linker>
+ <Add library="libPlandipitous-Windows.a" />
+ <Add directory="..\Project" />
+ </Linker>
+ <Unit filename="..\Demo\main.cpp" />
+ <Extensions>
+ <code_completion />
+ <debugger />
+ </Extensions>
+ </Project>
+</CodeBlocks_project_file>
49 Project/Plandipitous-Linux.cbp
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<CodeBlocks_project_file>
+ <FileVersion major="1" minor="6" />
+ <Project>
+ <Option title="Plandipitous" />
+ <Option pch_mode="2" />
+ <Option compiler="gcc" />
+ <Build>
+ <Target title="Debug">
+ <Option output="libPlandipitous-Linux" prefix_auto="1" extension_auto="1" />
+ <Option working_dir="" />
+ <Option object_output="obj/Debug/" />
+ <Option type="2" />
+ <Option compiler="gcc" />
+ <Option createDefFile="1" />
+ <Compiler>
+ <Add option="-Wall" />
+ <Add option="-g" />
+ </Compiler>
+ </Target>
+ <Target title="Release">
+ <Option output="libPlandipitous-Linux" prefix_auto="1" extension_auto="1" />
+ <Option working_dir="" />
+ <Option object_output="obj/Release/" />
+ <Option type="2" />
+ <Option compiler="gcc" />
+ <Option createDefFile="1" />
+ <Compiler>
+ <Add option="-Wall" />
+ <Add option="-O2" />
+ </Compiler>
+ <Linker>
+ <Add option="-s" />
+ </Linker>
+ </Target>
+ </Build>
+ <Compiler>
+ <Add directory="../Include" />
+ <Add directory="../../boost" />
+ </Compiler>
+ <Unit filename="../Include/Plandipitous.hpp" />
+ <Unit filename="../Source/Plandipitous.cpp" />
+ <Unit filename="../Source/rc_shortest_paths.cpp" />
+ <Extensions>
+ <code_completion />
+ <debugger />
+ </Extensions>
+ </Project>
+</CodeBlocks_project_file>
9 Project/Plandipitous-Linux.workspace
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<CodeBlocks_workspace_file>
+ <Workspace title="Workspace">
+ <Project filename="Plandipitous-Linux.cbp" />
+ <Project filename="Plandipitous-Demo-Linux.cbp" active="1">
+ <Depends filename="Plandipitous-Linux.cbp" />
+ </Project>
+ </Workspace>
+</CodeBlocks_workspace_file>
49 Project/Plandipitous-Windows.cbp
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<CodeBlocks_project_file>
+ <FileVersion major="1" minor="6" />
+ <Project>
+ <Option title="Plandipitous" />
+ <Option pch_mode="2" />
+ <Option compiler="gcc" />
+ <Build>
+ <Target title="Debug">
+ <Option output="libPlandipitous-Windows" prefix_auto="1" extension_auto="1" />
+ <Option working_dir="" />
+ <Option object_output="obj\Debug\" />
+ <Option type="2" />
+ <Option compiler="gcc" />
+ <Option createDefFile="1" />
+ <Compiler>
+ <Add option="-Wall" />
+ <Add option="-g" />
+ </Compiler>
+ </Target>
+ <Target title="Release">
+ <Option output="libPlandipitous-Windows" prefix_auto="1" extension_auto="1" />
+ <Option working_dir="" />
+ <Option object_output="obj\Release\" />
+ <Option type="2" />
+ <Option compiler="gcc" />
+ <Option createDefFile="1" />
+ <Compiler>
+ <Add option="-Wall" />
+ <Add option="-O2" />
+ </Compiler>
+ <Linker>
+ <Add option="-s" />
+ </Linker>
+ </Target>
+ </Build>
+ <Compiler>
+ <Add directory="..\..\boost" />
+ <Add directory="..\Include" />
+ </Compiler>
+ <Unit filename="..\Include\Plandipitous.hpp" />
+ <Unit filename="..\Source\Plandipitous.cpp" />
+ <Unit filename="..\Source\rc_shortest_paths.cpp" />
+ <Extensions>
+ <code_completion />
+ <debugger />
+ </Extensions>
+ </Project>
+</CodeBlocks_project_file>
9 Project/Plandipitous-Windows.workspace
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<CodeBlocks_workspace_file>
+ <Workspace title="Workspace">
+ <Project filename="Plandipitous-Windows.cbp" />
+ <Project filename="Plandipitous-Demo-Windows.cbp" active="1">
+ <Depends filename="Plandipitous-Windows.cbp" />
+ </Project>
+ </Workspace>
+</CodeBlocks_workspace_file>
0  README
No changes.
220 Source/Plandipitous.cpp
@@ -0,0 +1,220 @@
+
+#include <boost/graph/adjacency_list.hpp>
+#include <boost/graph/r_c_shortest_paths.hpp>
+using namespace boost;
+
+#include <set>
+#include <vector>
+#include <iostream>
+using namespace std;
+
+namespace Plandipitous
+{
+
+
+struct VertProp
+{
+ VertProp() : min_cost(0), max_cost(0) {}
+ VertProp(int min, int max) : min_cost(min), max_cost(max) {}
+ int min_cost;
+ int max_cost;
+};
+
+struct ArcProp
+{
+ ArcProp(int cost) : arc_cost(cost) {}
+ int arc_cost;
+};
+
+typedef adjacency_list<
+ vecS,vecS,directedS,VertProp,ArcProp
+> GraphType;
+
+
+// ResourceContainer model
+struct ResourceContainer
+{
+ int time;
+ int cost;
+
+ ResourceContainer(int time_, int cost_) : time(time_), cost(cost_) {}
+
+ ResourceContainer& operator=( const ResourceContainer& other )
+ {
+ if( this == &other )
+ return *this;
+ this->~ResourceContainer();
+ new( this ) ResourceContainer( other );
+ return *this;
+ }
+};
+
+bool operator==( const ResourceContainer& a,
+ const ResourceContainer& b )
+{
+ // TODO: Return true iff all the resources in container 1 equal container 2.
+ return (a.time == b.time) && (a.cost == b.cost);
+}
+
+bool operator<( const ResourceContainer& a,
+ const ResourceContainer& b )
+{
+ // TODO: Impose a total ordering on resource containers. That is,
+ // if resource X is the same, check resource Y, and so forth.
+ return a.time == b.time? a.cost < b.cost : a.time < b.time;
+}
+
+// ResourceExtensionFunction model
+class ResourceExtensionFunction
+{
+public:
+ inline bool operator()( const GraphType& g,
+ ResourceContainer& new_cont,
+ const ResourceContainer& old_cont,
+ graph_traits<GraphType>::edge_descriptor ed
+ ) const
+ {
+ const ArcProp& arc_prop = get( edge_bundle, g )[ed];
+ const VertProp& vert_prop = get( vertex_bundle, g )[target( ed, g )];
+
+ // TODO: new container resources = old container resources + action costs.
+ // (I think costs have to be added rather than subtracted because the dominance
+ // function is using the <= operator to look for lower resource consumptions.)
+
+ new_cont.time = old_cont.time + 1;
+ new_cont.cost = old_cont.cost + arc_prop.arc_cost;
+
+ std::cout << "Time " << new_cont.time << " cost " << old_cont.cost << " -> " << new_cont.cost << std::endl;
+
+ // TODO: Return true iff the extension is feasible.
+ return new_cont.cost <= vert_prop.max_cost && new_cont.cost >= vert_prop.min_cost;
+ }
+};
+
+// DominanceFunction model
+class DominanceFunction
+{
+public:
+ inline bool operator()( const ResourceContainer& res_cont_1,
+ const ResourceContainer& res_cont_2 ) const
+ {
+
+ // TODO: Return true if all the resources in container 1 are <= to container 2.
+ // (Or == for nominal (non-numeric) properties.)
+ bool dominated = res_cont_1.time <= res_cont_2.time && res_cont_1.cost == res_cont_2.cost ;
+
+ std::cout << "time: " << res_cont_1.time << "/" << res_cont_2.time << " cost: " << res_cont_1.cost << "/" << res_cont_2.cost << std::endl;
+
+ return dominated;
+
+ // must be "<=" here!!!
+ // must NOT be "<"!!!
+ // this is not a contradiction to the documentation
+ // the documentation says:
+ // "A label $l_1$ dominates a label $l_2$ if and only if both are resident
+ // at the same vertex, and if, for each resource, the resource consumption
+ // of $l_1$ is less than or equal to the resource consumption of $l_2$,
+ // and if there is at least one resource where $l_1$ has a lower resource
+ // consumption than $l_2$."
+ // one can think of a new label with a resource consumption equal to that
+ // of an old label as being dominated by that old label, because the new
+ // one will have a higher number and is created at a later point in time,
+ // so one can implicitly use the number or the creation time as a resource
+ // for tie-breaking
+ }
+};
+
+void do_test_2()
+{
+ GraphType g;
+
+ typedef GraphType::vertex_descriptor vd;
+
+ vd start = add_vertex( VertProp(-20,20), g );
+ vd node3 = add_vertex( VertProp(-20,20), g );
+ vd node5 = add_vertex( VertProp(-20,20), g );
+ vd goal = add_vertex( VertProp(2,2), g );
+
+ typedef GraphType::edge_descriptor ed;
+
+ add_edge( start, node3, ArcProp(3), g );
+ add_edge( start, node3, ArcProp(-3), g );
+ add_edge( node3, start, ArcProp(0), g );
+
+ add_edge( start, node5, ArcProp(5), g );
+ add_edge( start, node5, ArcProp(-5), g );
+ add_edge( node5, start, ArcProp(0), g );
+
+ add_edge( start, goal, ArcProp(0), g );
+
+ std::vector< std::vector<ed> > opt_solutions;
+
+ std::vector<std::vector<ed> > opt_solutions_spptw;
+ std::vector<ResourceContainer> pareto_opt_rcs_spptw;
+
+ r_c_shortest_paths
+ ( g,
+ get( vertex_index, g ),
+ get( vertex_index, g ),
+ start,
+ goal,
+ opt_solutions_spptw,
+ pareto_opt_rcs_spptw,
+ ResourceContainer( 0, 0 ),
+ ResourceExtensionFunction(),
+ DominanceFunction(),
+ std::allocator
+ <r_c_shortest_paths_label
+ <GraphType, ResourceContainer> >(),
+ default_r_c_shortest_paths_visitor() );
+
+ std::cout << "Number of optimal solutions: ";
+ std::cout << static_cast<int>( opt_solutions.size() ) << std::endl;
+ for( int i = 0; i < static_cast<int>( opt_solutions.size() ); ++i )
+ {
+ std::cout << "The " << i << "th shortest path is: ";
+ std::cout << std::endl;
+ for( int j = static_cast<int>( opt_solutions_spptw[i].size() ) - 1;
+ j >= 0;
+ --j )
+ std::cout << source( opt_solutions_spptw[i][j], g ) << std::endl;
+ std::cout << "cost: " << pareto_opt_rcs_spptw[i].cost << std::endl;
+ std::cout << "time: " << pareto_opt_rcs_spptw[i].time << std::endl;
+ }
+
+ // utility function check_r_c_path example
+ std::cout << std::endl;
+ bool b_is_a_path_at_all = false;
+ bool b_feasible = false;
+ bool b_correctly_extended = false;
+ ResourceContainer actual_final_resource_levels( 0, 0 );
+ ed ed_last_extended_arc;
+ check_r_c_path( g,
+ opt_solutions_spptw[0],
+ ResourceContainer( 0, 0 ),
+ true,
+ pareto_opt_rcs_spptw[0],
+ actual_final_resource_levels,
+ ResourceExtensionFunction(),
+ b_is_a_path_at_all,
+ b_feasible,
+ b_correctly_extended,
+ ed_last_extended_arc );
+ if( !b_is_a_path_at_all )
+ std::cout << "Not a path." << std::endl;
+ if( !b_feasible )
+ std::cout << "Not a feasible path." << std::endl;
+ if( !b_correctly_extended )
+ std::cout << "Not correctly extended." << std::endl;
+ if( b_is_a_path_at_all && b_feasible && b_correctly_extended )
+ {
+ std::cout << "Actual final resource levels:" << std::endl;
+ std::cout << "Cost: " << actual_final_resource_levels.cost << std::endl;
+ std::cout << "Time: " << actual_final_resource_levels.time << std::endl;
+ std::cout << "OK." << std::endl;
+ }
+
+}
+
+
+}
354 Source/rc_shortest_paths.cpp
@@ -0,0 +1,354 @@
+// Copyright Michael Drexl 2005, 2006.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://boost.org/LICENSE_1_0.txt)
+
+// Example use of the resource-constrained shortest paths algorithm.
+#include <boost/config.hpp>
+
+#ifdef BOOST_MSVC
+# pragma warning(disable: 4267)
+#endif
+
+#include <boost/graph/adjacency_list.hpp>
+
+#include <boost/graph/r_c_shortest_paths.hpp>
+#include <iostream>
+
+using namespace boost;
+
+struct SPPRC_Example_Graph_Vert_Prop
+{
+ SPPRC_Example_Graph_Vert_Prop( int n = 0, int e = 0, int l = 0 )
+ : num( n ), eat( e ), lat( l ) {}
+ int num;
+ // earliest arrival time
+ int eat;
+ // latest arrival time
+ int lat;
+};
+
+struct SPPRC_Example_Graph_Arc_Prop
+{
+ SPPRC_Example_Graph_Arc_Prop( int n = 0, int c = 0, int t = 0 )
+ : num( n ), cost( c ), time( t ) {}
+ int num;
+ // traversal cost
+ int cost;
+ // traversal time
+ int time;
+};
+
+typedef adjacency_list<vecS,
+ vecS,
+ directedS,
+ SPPRC_Example_Graph_Vert_Prop,
+ SPPRC_Example_Graph_Arc_Prop>
+ SPPRC_Example_Graph;
+
+// data structures for spp without resource constraints:
+// ResourceContainer model
+struct spp_no_rc_res_cont
+{
+ spp_no_rc_res_cont( int c = 0 ) : cost( c ) {};
+ spp_no_rc_res_cont& operator=( const spp_no_rc_res_cont& other )
+ {
+ if( this == &other )
+ return *this;
+ this->~spp_no_rc_res_cont();
+ new( this ) spp_no_rc_res_cont( other );
+ return *this;
+ }
+ int cost;
+};
+
+bool operator==( const spp_no_rc_res_cont& res_cont_1,
+ const spp_no_rc_res_cont& res_cont_2 )
+{
+ return ( res_cont_1.cost == res_cont_2.cost );
+}
+
+bool operator<( const spp_no_rc_res_cont& res_cont_1,
+ const spp_no_rc_res_cont& res_cont_2 )
+{
+ return ( res_cont_1.cost < res_cont_2.cost );
+}
+
+// ResourceExtensionFunction model
+class ref_no_res_cont
+{
+public:
+ inline bool operator()( const SPPRC_Example_Graph& g,
+ spp_no_rc_res_cont& new_cont,
+ const spp_no_rc_res_cont& old_cont,
+ graph_traits
+ <SPPRC_Example_Graph>::edge_descriptor ed ) const
+ {
+ new_cont.cost = old_cont.cost + g[ed].cost;
+ return true;
+ }
+};
+
+// DominanceFunction model
+class dominance_no_res_cont
+{
+public:
+ inline bool operator()( const spp_no_rc_res_cont& res_cont_1,
+ const spp_no_rc_res_cont& res_cont_2 ) const
+ {
+ // must be "<=" here!!!
+ // must NOT be "<"!!!
+ return res_cont_1.cost <= res_cont_2.cost;
+ // this is not a contradiction to the documentation
+ // the documentation says:
+ // "A label $l_1$ dominates a label $l_2$ if and only if both are resident
+ // at the same vertex, and if, for each resource, the resource consumption
+ // of $l_1$ is less than or equal to the resource consumption of $l_2$,
+ // and if there is at least one resource where $l_1$ has a lower resource
+ // consumption than $l_2$."
+ // one can think of a new label with a resource consumption equal to that
+ // of an old label as being dominated by that old label, because the new
+ // one will have a higher number and is created at a later point in time,
+ // so one can implicitly use the number or the creation time as a resource
+ // for tie-breaking
+ }
+};
+// end data structures for spp without resource constraints:
+
+// data structures for shortest path problem with time windows (spptw)
+// ResourceContainer model
+struct spp_spptw_res_cont
+{
+ spp_spptw_res_cont( int c = 0, int t = 0 ) : cost( c ), time( t ) {}
+ spp_spptw_res_cont& operator=( const spp_spptw_res_cont& other )
+ {
+ if( this == &other )
+ return *this;
+ this->~spp_spptw_res_cont();
+ new( this ) spp_spptw_res_cont( other );
+ return *this;
+ }
+ int cost;
+ int time;
+};
+
+bool operator==( const spp_spptw_res_cont& res_cont_1,
+ const spp_spptw_res_cont& res_cont_2 )
+{
+ return ( res_cont_1.cost == res_cont_2.cost
+ && res_cont_1.time == res_cont_2.time );
+}
+
+bool operator<( const spp_spptw_res_cont& res_cont_1,
+ const spp_spptw_res_cont& res_cont_2 )
+{
+ if( res_cont_1.cost > res_cont_2.cost )
+ return false;
+ if( res_cont_1.cost == res_cont_2.cost )
+ return res_cont_1.time < res_cont_2.time;
+ return true;
+}
+
+// ResourceExtensionFunction model
+class ref_spptw
+{
+public:
+ inline bool operator()( const SPPRC_Example_Graph& g,
+ spp_spptw_res_cont& new_cont,
+ const spp_spptw_res_cont& old_cont,
+ graph_traits
+ <SPPRC_Example_Graph>::edge_descriptor ed ) const
+ {
+ const SPPRC_Example_Graph_Arc_Prop& arc_prop =
+ get( edge_bundle, g )[ed];
+ const SPPRC_Example_Graph_Vert_Prop& vert_prop =
+ get( vertex_bundle, g )[target( ed, g )];
+ new_cont.cost = old_cont.cost + arc_prop.cost;
+ int& i_time = new_cont.time;
+ i_time = old_cont.time + arc_prop.time;
+ i_time < vert_prop.eat ? i_time = vert_prop.eat : 0;
+ return i_time <= vert_prop.lat ? true : false;
+ }
+};
+
+// DominanceFunction model
+class dominance_spptw
+{
+public:
+ inline bool operator()( const spp_spptw_res_cont& res_cont_1,
+ const spp_spptw_res_cont& res_cont_2 ) const
+ {
+ // must be "<=" here!!!
+ // must NOT be "<"!!!
+ return res_cont_1.cost <= res_cont_2.cost
+ && res_cont_1.time <= res_cont_2.time;
+ // this is not a contradiction to the documentation
+ // the documentation says:
+ // "A label $l_1$ dominates a label $l_2$ if and only if both are resident
+ // at the same vertex, and if, for each resource, the resource consumption
+ // of $l_1$ is less than or equal to the resource consumption of $l_2$,
+ // and if there is at least one resource where $l_1$ has a lower resource
+ // consumption than $l_2$."
+ // one can think of a new label with a resource consumption equal to that
+ // of an old label as being dominated by that old label, because the new
+ // one will have a higher number and is created at a later point in time,
+ // so one can implicitly use the number or the creation time as a resource
+ // for tie-breaking
+ }
+};
+// end data structures for shortest path problem with time windows (spptw)
+
+// example graph structure and cost from
+// http://www.boost.org/libs/graph/example/dijkstra-example.cpp
+const int num_nodes = 5;
+enum nodes { A, B, C, D, E };
+char name[] = "ABCDE";
+
+int do_test()
+{
+ SPPRC_Example_Graph g;
+
+ add_vertex( SPPRC_Example_Graph_Vert_Prop( A, 0, 0 ), g );
+ add_vertex( SPPRC_Example_Graph_Vert_Prop( B, 5, 20 ), g );
+ add_vertex( SPPRC_Example_Graph_Vert_Prop( C, 6, 10 ), g );
+ add_vertex( SPPRC_Example_Graph_Vert_Prop( D, 3, 12 ), g );
+ add_vertex( SPPRC_Example_Graph_Vert_Prop( E, 0, 100 ), g );
+
+ add_edge( A, C, SPPRC_Example_Graph_Arc_Prop( 0, 1, 5 ), g );
+ add_edge( B, B, SPPRC_Example_Graph_Arc_Prop( 1, 2, 5 ), g );
+ add_edge( B, D, SPPRC_Example_Graph_Arc_Prop( 2, 1, 2 ), g );
+ add_edge( B, E, SPPRC_Example_Graph_Arc_Prop( 3, 2, 7 ), g );
+ add_edge( C, B, SPPRC_Example_Graph_Arc_Prop( 4, 7, 3 ), g );
+ add_edge( C, D, SPPRC_Example_Graph_Arc_Prop( 5, 3, 8 ), g );
+ add_edge( D, E, SPPRC_Example_Graph_Arc_Prop( 6, 1, 3 ), g );
+ add_edge( E, A, SPPRC_Example_Graph_Arc_Prop( 7, 1, 5 ), g );
+ add_edge( E, B, SPPRC_Example_Graph_Arc_Prop( 8, 1, 4 ), g );
+
+
+ // the unique shortest path from A to E in the dijkstra-example.cpp is
+ // A -> C -> D -> E
+ // its length is 5
+ // the following code also yields this result
+
+ // with the above time windows, this path is infeasible
+ // now, there are two shortest paths that are also feasible with respect to
+ // the vertex time windows:
+ // A -> C -> B -> D -> E and
+ // A -> C -> B -> E
+ // however, the latter has a longer total travel time and is therefore not
+ // pareto-optimal, i.e., it is dominated by the former path
+ // therefore, the code below returns only the former path
+
+ // spp without resource constraints
+ graph_traits<SPPRC_Example_Graph>::vertex_descriptor s = A;
+ graph_traits<SPPRC_Example_Graph>::vertex_descriptor t = E;
+
+ std::vector
+ <std::vector
+ <graph_traits<SPPRC_Example_Graph>::edge_descriptor> >
+ opt_solutions;
+ std::vector<spp_no_rc_res_cont> pareto_opt_rcs_no_rc;
+
+ r_c_shortest_paths
+ ( g,
+ get( &SPPRC_Example_Graph_Vert_Prop::num, g ),
+ get( &SPPRC_Example_Graph_Arc_Prop::num, g ),
+ s,
+ t,
+ opt_solutions,
+ pareto_opt_rcs_no_rc,
+ spp_no_rc_res_cont( 0 ),
+ ref_no_res_cont(),
+ dominance_no_res_cont(),
+ std::allocator
+ <r_c_shortest_paths_label
+ <SPPRC_Example_Graph, spp_no_rc_res_cont> >(),
+ default_r_c_shortest_paths_visitor() );
+
+ std::cout << "SPP without resource constraints:" << std::endl;
+ std::cout << "Number of optimal solutions: ";
+ std::cout << static_cast<int>( opt_solutions.size() ) << std::endl;
+ for( int i = 0; i < static_cast<int>( opt_solutions.size() ); ++i )
+ {
+ std::cout << "The " << i << "th shortest path from A to E is: ";
+ std::cout << std::endl;
+ for( int j = static_cast<int>( opt_solutions[i].size() ) - 1; j >= 0; --j )
+ std::cout << name[source( opt_solutions[i][j], g )] << std::endl;
+ std::cout << "E" << std::endl;
+ std::cout << "Length: " << pareto_opt_rcs_no_rc[i].cost << std::endl;
+ }
+ std::cout << std::endl;
+
+ // spptw
+ std::vector
+ <std::vector
+ <graph_traits<SPPRC_Example_Graph>::edge_descriptor> >
+ opt_solutions_spptw;
+ std::vector<spp_spptw_res_cont> pareto_opt_rcs_spptw;
+
+ r_c_shortest_paths
+ ( g,
+ get( &SPPRC_Example_Graph_Vert_Prop::num, g ),
+ get( &SPPRC_Example_Graph_Arc_Prop::num, g ),
+ s,
+ t,
+ opt_solutions_spptw,
+ pareto_opt_rcs_spptw,
+ spp_spptw_res_cont( 0, 0 ),
+ ref_spptw(),
+ dominance_spptw(),
+ std::allocator
+ <r_c_shortest_paths_label
+ <SPPRC_Example_Graph, spp_spptw_res_cont> >(),
+ default_r_c_shortest_paths_visitor() );
+
+ std::cout << "SPP with time windows:" << std::endl;
+ std::cout << "Number of optimal solutions: ";
+ std::cout << static_cast<int>( opt_solutions.size() ) << std::endl;
+ for( int i = 0; i < static_cast<int>( opt_solutions.size() ); ++i )
+ {
+ std::cout << "The " << i << "th shortest path from A to E is: ";
+ std::cout << std::endl;
+ for( int j = static_cast<int>( opt_solutions_spptw[i].size() ) - 1;
+ j >= 0;
+ --j )
+ std::cout << name[source( opt_solutions_spptw[i][j], g )] << std::endl;
+ std::cout << "E" << std::endl;
+ std::cout << "Length: " << pareto_opt_rcs_spptw[i].cost << std::endl;
+ std::cout << "Time: " << pareto_opt_rcs_spptw[i].time << std::endl;
+ }
+
+ // utility function check_r_c_path example
+ std::cout << std::endl;
+ bool b_is_a_path_at_all = false;
+ bool b_feasible = false;
+ bool b_correctly_extended = false;
+ spp_spptw_res_cont actual_final_resource_levels( 0, 0 );
+ graph_traits<SPPRC_Example_Graph>::edge_descriptor ed_last_extended_arc;
+ check_r_c_path( g,
+ opt_solutions_spptw[0],
+ spp_spptw_res_cont( 0, 0 ),
+ true,
+ pareto_opt_rcs_spptw[0],
+ actual_final_resource_levels,
+ ref_spptw(),
+ b_is_a_path_at_all,
+ b_feasible,
+ b_correctly_extended,
+ ed_last_extended_arc );
+ if( !b_is_a_path_at_all )
+ std::cout << "Not a path." << std::endl;
+ if( !b_feasible )
+ std::cout << "Not a feasible path." << std::endl;
+ if( !b_correctly_extended )
+ std::cout << "Not correctly extended." << std::endl;
+ if( b_is_a_path_at_all && b_feasible && b_correctly_extended )
+ {
+ std::cout << "Actual final resource levels:" << std::endl;
+ std::cout << "Length: " << actual_final_resource_levels.cost << std::endl;
+ std::cout << "Time: " << actual_final_resource_levels.time << std::endl;
+ std::cout << "OK." << std::endl;
+ }
+
+ return 0;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.