00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "base/commandlineflags.h"
00015 #include "base/logging.h"
00016 #include "graph/ebert_graph.h"
00017 #include "graph/linear_assignment.h"
00018
00019 namespace operations_research {
00020
00021
00022
00023
00024 void AssignmentOn4x4Matrix() {
00025 LOG(INFO) << "Assignment on 4x4 Matrix";
00026 const int kNumSources = 4;
00027 const int kNumTargets = 4;
00028 const CostValue kCost[kNumSources][kNumTargets] = {
00029 { 90, 76, 75, 80 },
00030 { 35, 85, 55, 65 },
00031 { 125, 95, 90, 105 },
00032 { 45, 110, 95, 115 }
00033 };
00034 const CostValue kExpectedCost =
00035 kCost[0][3] + kCost[1][2] + kCost[2][1] + kCost[3][0];
00036 ForwardStarGraph graph(
00037 kNumSources + kNumTargets, kNumSources * kNumTargets);
00038 LinearSumAssignment<ForwardStarGraph> assignment(graph, kNumSources);
00039 for (NodeIndex source = 0; source < kNumSources; ++source) {
00040 for (NodeIndex target = 0; target < kNumTargets; ++target) {
00041 ArcIndex arc = graph.AddArc(source, kNumSources + target);
00042 assignment.SetArcCost(arc, kCost[source][target]);
00043 }
00044 }
00045 CHECK(assignment.ComputeAssignment());
00046 CostValue total_cost = assignment.GetCost();
00047 CHECK_EQ(kExpectedCost, total_cost);
00048 }
00049
00050 }
00051
00052 int main(int argc, char **argv) {
00053 google::ParseCommandLineFlags(&argc, &argv, true);
00054 operations_research::AssignmentOn4x4Matrix();
00055 return 0;
00056 }