X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=mtp.git;a=blobdiff_plain;f=mtp_tracker.cc;h=b4e70abd6dad1e01362eb4a47cb16e0ba1016f56;hp=c7c6602eac5c89c76079cdfdad0d2efab0c19471;hb=c7d5cdf1982dacc5451f79599041b2e95524d3f7;hpb=2b42f849b86f2517e7e0fbaf498e307c1d48dd2a diff --git a/mtp_tracker.cc b/mtp_tracker.cc index c7c6602..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 <> 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