![]() ![]()
|
This article covers the so-called "min-cost flow" problem, which has many applications for both TopCoder competitors and professional programmers. The article is targeted to readers who are not familiar with the subject, with a focus more on providing a general understanding of the ideas involved rather than heavy theory or technical details; for a more in-depth look at this topic, check out the references at the end of this article, in particular [1]. In addition, readers of this article should be familiar with the basic concepts of graph theory -- including shortest paths [4], paths with negative cost arcs, negative cycles [1] -- and maximum flow theory's basic algorithms [3]. The article is divided into three parts. In Part 1, we'll look at the problem itself. The next part will describe three basic algorithms, and Part 3 some applications to the problem will be covered in Part 3. Statement of the Problem Let We associate with each vertex For simplification, let's call G a transportation network and write ![]() Figure 1. An example of the transportation network. In this we have 2 supply vertexes (with supply values 5 and 2), 3 demand vertexes (with demand values 1, 4 and 2), and 1 transshipment node. Each edge has two numbers, capacity and cost, divided by comma. Representing the flow on arc ![]() subject to ![]() The first constraint states that the total outflow of a node minus the total inflow of the node must be equal to mass balance (supply/demand value) of this node. This is known as the mass balance constraints. Next, the flow bound constraints model physical capacities or restrictions imposed on the flow's range. As you can see, this optimization model describes a typical relationship between warehouses and shops, for example, in a case where we have only one kind of product. We need to satisfy the demand of each shop by transferring goods from the subset of warehouses, while minimizing the expenses on transportation. This problem could be solved using simplex-method, but in this article we concentrate on some other ideas related to network flow theory. Before we move on to the three basic algorithms used to solve the minimum cost flow problem, let's review the necessary theoretical base. Finding a solution If We can easily avoid this situation, however, if we add a special node r with the supply/demand value Consider the vertex r as a rubbish or scrap dump. If the shops demand is less than what the warehouse supplies, then we have to eject the useless goods as rubbish. Otherwise, we take the missing goods from the dump. This would be considered shady in real life, of course, but for our purposes it is very convenient. Keep in mind that, in this case, we cannot say what exactly the "solution" of the corrected (with scrap) problem is. And it is up to the reader how to classify the emergency uses of the "dump." For example, we can suggest that goods remain in the warehouses or some of the shop's demands remain unsatisfied. Even if we have Let us introduce a source node s and a sink node t. For each node ![]() Figure 2. Maximum flow in the transformed network. For simplicity we are ignoring the costs. The new network is called a transformed network. Next, we solve a maximum flow problem from s to t (ignoring costs, see fig.2). If the maximum flow saturates all the source and sink arcs, then the problem has a feasible solution; otherwise, it is infeasible. As for why this approach works, we'll leave its proof to the reader. Having found a maximum flow, we can now remove source, sink, and all adjacent arcs and obtain a feasible flow in G. How do we detect whether the flow is optimal or not? Does this flow minimize costs of the objective function z? We usually verify "optimality conditions" for the answer to these questions, but let us put them on hold for a moment and discuss some assumptions. Now, suppose that we have a network that has a feasible solution. Does it have an optimal solution? If our network contains the negative cost cycle of infinite capacity then the objective function will be unbounded. However, in some tasks, we are able to assign finite capacity to each uncapacitated edge escaping such a situation. So, from the theoretical point of view, for any minimum cost flow problem we have to check some conditions: The supply/demand balance, the existence of a feasible solution, and the last situation with uncapacitated negative cycles. These are necessary conditions for resolving the problem. But from the practical point of view, we can check the conditions while the solution is being found. Assumptions Assumption 1. All data (uij, cij, bi) are integral. Assumption 2. The network is directed. To transform an undirected case to a directed one, we replace each undirected edge connecting vertexes i and j by two directed edges Assumption 3. All costs associated with edges are nonnegative. For each vertex ![]() How does our objective value change? Let's denote reduced value by ![]() For other values of ![]() For a fixed Theorem 1. For any node potential ![]() The following result contains very useful properties of reduced costs. Theorem 2. Let G be a transportation network. Suppose P is a directed path from ![]() Suppose W is a directed cycle. Then for any node potential ![]() This theorem implies the following reasoning. Let's introduce a vertex s and for each node ![]() Since, Remember this reduced cost technique, since it appears in many applications and other algorithms (for example, Johnson's algorithm for all pair shortest path in sparse networks uses it [2]). Assumption 4. The supply/demand at the vertexes satisfy the condition This assumption is a consequence of the "Finding a Solution" section of this article. If the network doesn't satisfy the first part of this assumption, we can either say that the problem has no solution or make corresponding transformation according to the steps outlined in that section. If the second part of the assumption isn't met then the solution doesn't exist. By making these assumptions we do transform our original transportation network. However, many problems are often given in such a way which satisfies all the assumptions. Now that all the preparations are behind us, we can start to discuss the algorithms in Part 2. References |
|
|
Home |
About TopCoder |
Press Room |
Contact Us |
Careers |
Privacy |
Terms
Competitions | Cockpit |
| Copyright TopCoder, Inc. 2001- |