X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=mtp_tracker.cc;h=b4e70abd6dad1e01362eb4a47cb16e0ba1016f56;hb=c7d5cdf1982dacc5451f79599041b2e95524d3f7;hp=793b6729ec0c85bfc8298fa56af8198b10fb4f9d;hpb=f2e3ed51b2a5b2776c86223e873d765cb2b78c15;p=mtp.git diff --git a/mtp_tracker.cc b/mtp_tracker.cc index 793b672..b4e70ab 100644 --- a/mtp_tracker.cc +++ b/mtp_tracker.cc @@ -63,12 +63,15 @@ void MTPTracker::allocate(int t, int l) { } } + force_empty_first_frame = 0; + force_empty_last_frame = 0; + _edge_lengths = 0; _graph = 0; } void MTPTracker::write(ostream *os) { - (*os) << nb_locations << " " << nb_time_steps <> nb_locations >> nb_time_steps; + (*is) >> l >> t; - allocate(nb_time_steps, nb_locations); + allocate(t, l); for(int l = 0; l < nb_locations; l++) { for(int m = 0; m < nb_locations; m++) { @@ -116,6 +123,8 @@ void MTPTracker::read(istream *is) { } } + (*is) >> force_empty_first_frame >> force_empty_last_frame; + for(int l = 0; l < nb_locations; l++) { (*is) >> entrances[l]; } @@ -194,9 +203,6 @@ void MTPTracker::build_graph() { int nb_vertices = 2 + 2 * nb_time_steps * nb_locations; int nb_edges = - // The edges from the source to the first frame, and from the last - // frame to the sink - nb_locations * 2 + // The edges from the source to the entrances and from the exits // to the sink (in every time frames but the first for the // entrances, and last for the exits) @@ -206,6 +212,20 @@ void MTPTracker::build_graph() { // The edges inside the duplicated nodes nb_locations * nb_time_steps; + // Edges from the source to the first frame + if(force_empty_first_frame) { + nb_edges += nb_entrances; + } else { + nb_edges += nb_locations; + } + + // Edges from the last frame to the sink + if(force_empty_last_frame) { + nb_edges += nb_exits; + } else { + nb_edges += nb_locations; + } + int *node_from = new int[nb_edges]; int *node_to = new int[nb_edges]; @@ -229,19 +249,23 @@ void MTPTracker::build_graph() { // The edges from the source to the first time frame for(int l = 0; l < nb_locations; l++) { - node_from[e] = source; - node_to[e] = 1 + l + 0 * nb_locations; - _edge_lengths[e] = 0.0; - e++; + if(!force_empty_first_frame || entrances[l]) { + node_from[e] = source; + node_to[e] = 1 + l + 0 * nb_locations; + _edge_lengths[e] = 0.0; + e++; + } } // The edges from the last frame to the sink for(int l = 0; l < nb_locations; l++) { - node_from[e] = late_pair_node(nb_time_steps - 1, l); - node_to[e] = sink; - _edge_lengths[e] = 0.0; - e++; + if(!force_empty_last_frame || exits[l]) { + node_from[e] = late_pair_node(nb_time_steps - 1, l); + node_to[e] = sink; + _edge_lengths[e] = 0.0; + e++; + } } // The edges between frames, corresponding to allowed motions