big graph cleaning; rewrite CP-SAT python layer; rewrite model_builder python layer; reorganize CP-SAT scheduling and packing code
This commit is contained in:
@@ -103,10 +103,7 @@ CostValue BuildAndSolveHungarianInstance(
|
||||
|
||||
template <typename GraphType>
|
||||
void DisplayAssignment(const LinearSumAssignment<GraphType>& assignment) {
|
||||
for (typename LinearSumAssignment<GraphType>::BipartiteLeftNodeIterator
|
||||
node_it(assignment);
|
||||
node_it.Ok(); node_it.Next()) {
|
||||
const NodeIndex left_node = node_it.Index();
|
||||
for (const auto left_node : assignment.BipartiteLeftNodes()) {
|
||||
const ArcIndex matching_arc = assignment.GetAssignmentArc(left_node);
|
||||
const NodeIndex right_node = assignment.Head(matching_arc);
|
||||
VLOG(5) << "assigned (" << left_node << ", " << right_node
|
||||
|
||||
@@ -56,7 +56,7 @@ void MinCostFlowOn4x4Matrix() {
|
||||
min_cost_flow.SetNodeSupply(kNumSources + target, -1);
|
||||
}
|
||||
CHECK(min_cost_flow.Solve());
|
||||
CHECK_EQ(MinCostFlow::OPTIMAL, min_cost_flow.status());
|
||||
CHECK_EQ(GenericMinCostFlow<Graph>::OPTIMAL, min_cost_flow.status());
|
||||
CostValue total_flow_cost = min_cost_flow.GetOptimalCost();
|
||||
CHECK_EQ(kExpectedCost, total_flow_cost);
|
||||
}
|
||||
|
||||
@@ -22,15 +22,16 @@
|
||||
|
||||
namespace operations_research {
|
||||
struct Arc {
|
||||
std::pair<NodeIndex, NodeIndex> nodes;
|
||||
FlowQuantity capacity;
|
||||
FlowQuantity unit_cost;
|
||||
std::pair<SimpleMinCostFlow::NodeIndex, SimpleMinCostFlow::NodeIndex> nodes;
|
||||
SimpleMinCostFlow::FlowQuantity capacity;
|
||||
SimpleMinCostFlow::FlowQuantity unit_cost;
|
||||
};
|
||||
|
||||
void SolveMinCostFlow() {
|
||||
// Define supply of each node.
|
||||
const std::vector<std::pair<NodeIndex, FlowQuantity> > supplies = {
|
||||
{0, 20}, {1, 0}, {2, 0}, {3, -5}, {4, -15}};
|
||||
const std::vector<
|
||||
std::pair<SimpleMinCostFlow::NodeIndex, SimpleMinCostFlow::FlowQuantity> >
|
||||
supplies = {{0, 20}, {1, 0}, {2, 0}, {3, -5}, {4, -15}};
|
||||
|
||||
// Define each arc
|
||||
// Can't use std::tuple<NodeIndex, NodeIndex, FlowQuantity>
|
||||
@@ -58,7 +59,7 @@ void SolveMinCostFlow() {
|
||||
if (status != SimpleMinCostFlow::OPTIMAL) {
|
||||
LOG(FATAL) << "Solving the max flow is not optimal!";
|
||||
}
|
||||
FlowQuantity total_flow_cost = min_cost_flow.OptimalCost();
|
||||
SimpleMinCostFlow::FlowQuantity total_flow_cost = min_cost_flow.OptimalCost();
|
||||
LOG(INFO) << "Minimum cost flow: " << total_flow_cost;
|
||||
LOG(INFO) << "";
|
||||
LOG(INFO) << "Arc : Flow / Capacity / Cost";
|
||||
|
||||
@@ -46,10 +46,9 @@ void PrintDimacsAssignmentProblem(
|
||||
absl::StrFormat("p asn %d %d\n", graph.num_nodes(), graph.num_arcs());
|
||||
CHECK_OK(file::WriteString(output, output_line, file::Defaults()));
|
||||
|
||||
for (typename LinearSumAssignment<GraphType>::BipartiteLeftNodeIterator
|
||||
node_it(assignment);
|
||||
node_it.Ok(); node_it.Next()) {
|
||||
output_line = absl::StrFormat("n %d\n", node_it.Index() + 1);
|
||||
for (const typename GraphType::NodeIndex left_node :
|
||||
assignment.BipartiteLeftNodes()) {
|
||||
output_line = absl::StrFormat("n %d\n", left_node + 1);
|
||||
CHECK_OK(file::WriteString(output, output_line, file::Defaults()));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user