diff --git a/examples/dimacs_assignment.cc b/examples/dimacs_assignment.cc index 9f961b34d3..2168f8a179 100644 --- a/examples/dimacs_assignment.cc +++ b/examples/dimacs_assignment.cc @@ -139,8 +139,16 @@ int solve_dimacs_assignment(int argc, char* argv[]) { LOG(FATAL) << error_message; } if (!FLAGS_assignment_problem_output_file.empty()) { - PrintDimacsAssignmentProblem(*assignment, + // The following tail array management stuff is done in a generic + // way so we can plug in different types of graphs for which the + // TailArrayManager template can be instantiated, even though we + // know the type of the graph explicitly. In this way, the type of + // the graph can be switched just by changing the graph type in + // this file and making no other changes to the code. + TailArrayManager tail_array_manager(graph); + PrintDimacsAssignmentProblem(*assignment, tail_array_manager, FLAGS_assignment_problem_output_file); + tail_array_manager.ReleaseTailArrayIfForwardGraph(); } CostValue hungarian_cost = 0.0; bool hungarian_solved = false; diff --git a/examples/print_dimacs_assignment.cc b/examples/print_dimacs_assignment.cc index 93f83bd3a9..1ecf803ac7 100644 --- a/examples/print_dimacs_assignment.cc +++ b/examples/print_dimacs_assignment.cc @@ -37,6 +37,7 @@ static void WriteOrDie(const char* buffer, void PrintDimacsAssignmentProblem( const LinearSumAssignment& assignment, + const TailArrayManager& tail_array_manager, const string& output_filename) { FILE* output = fopen(output_filename.c_str(), "w"); const ForwardStarGraph& graph(assignment.Graph()); @@ -55,6 +56,8 @@ void PrintDimacsAssignmentProblem( output); } + tail_array_manager.BuildTailArrayFromAdjacencyListsIfForwardGraph(); + for (ForwardStarGraph::ArcIterator arc_it(assignment.Graph()); arc_it.Ok(); arc_it.Next()) { diff --git a/examples/print_dimacs_assignment.h b/examples/print_dimacs_assignment.h index 3e100754fa..9e576dd4af 100644 --- a/examples/print_dimacs_assignment.h +++ b/examples/print_dimacs_assignment.h @@ -20,6 +20,7 @@ template class LinearSumAssignment; // http://lpsolve.sourceforge.net/5.5/DIMACS_asn.htm void PrintDimacsAssignmentProblem( const LinearSumAssignment& assignment, + const TailArrayManager& tail_array_manager, const string& output_filename); } // namespace operations_research