- El comercio electrónico [6]
1.7 Tendencias y retos de la logística inversa
As discussed in Section 2.4.2, the Berger/Shor New 2-Approximation algorithm was selected for this project to provide approximations of solutions for input graphs that brute force could not because of the input size. In general, approximation algorithms may not produce the best rankings for a graph, but they can produce acceptable solutions for cyclic graphs in polynomial time. This algorithm was selected because of its polynomial runtime and its factor of two correctness, which suggested comparable results to the brute force approach for larger graphs.
Our version of the Berger/Shor New 2-Approximation algorithm utilized the addition of topological sort to develop a total ordering from the acyclic output graph, and several preprocessors to improve the correctness of the output. The Berger/Shor algorithm was intended to solve the Maximum Acyclic Subgraph problem, so by design, it only returned an acyclic subgraph. Thus, topological sort could be applied to transform the output acyclic graph into a ranked total ordering, or ordering of all nodes in a graph.
Additionally, we designed our algorithm to preprocess the input for better results. Our first preprocessor was the strongly connected components preprocessor, which would determine the sets of nodes that were part of strongly connected components within the graph. These strongly connected components could then be evaluated by the Berger/Shor approximation, as any edges not included within a component are not part of cycles, thus they do not need to be removed. Our second preprocessor involved rearranging the order of nodes to be approximated within each strongly connected component. This ordering impacts which edges are removed during the approximation, as the removal of one set of edges earlier in the approximation may change whether another node has its incoming or outgoing edges removed, potentially resulting in a more accurate approximation.
3.4.2.1: Proofs
Lemma 1: The resulting graph is acyclic.
Proof: Suppose a cycle exists of vertices (v1, v2, … , vn, v1). After evaluation of vertex vi in this cycle, where 1 ≤ i ≤ n, either the edge <vi-1, vi> or <vi, vi+1> has been discarded by removing either the incoming or outgoing edges of vi. Thus, a cycle can no longer be formed from v1 to vn [1].
Lemma 2: The output provided by this algorithm is always within a factor of two of the correct answer.
Proof: Each node vin graph G is evaluated once. The larger of the two sets of edges for each v is transferred to the output graph, while the smaller of the two sets is discarded. Therefore, at least half of all edges in the input edge set A are present in the output edge set A’, meaning that |A’| ≥ (½)|A|. Thus, the output graph is always within a factor of two of the potentially cyclic input, so it must be within a factor of two for the correct acyclic output [1].
Lemma 3: The algorithm terminates with a total ordering.
Proof: Following Lemma 1, the output graph from this algorithm is acyclic [1]. Therefore, a total ordering can be generated utilizing topological sort without entering an infinite loop.
3.4.2.2: Pseudocode
The following pseudocode provides a high-level description of how the Berger/Shor New 2-Approximation algorithm works. It begins with an input graph G with vertex set V and edge set E, and outputs an acyclic graph G’ with vertex set V and modified edge set E’. The algorithm first determines the edges involved in each strongly connected component in the graph, removing them from the output graph. The remaining edges do not contribute to cycles and therefore can remain in the final graph. Then, the algorithm conducts the Berger/Shor approximation process on each strongly connected component, storing the resulting edges into the output graph.
Within the Berger/Shor approximation function itself, the strongly connected component input is received, while the acyclic component with edges removed is output. This function iterates through each vertex v in the input vertex set V and determines v’s indegree and outdegree. If the indegree is larger than the outdegree for v, v’s outgoing edges are removed from E, and v’s incoming edges are copied over to E’ before being removed from E. Otherwise, v’s incoming edges are removed from E, and v’s outgoing edges are copied to E’ before being removed from E. Once this completes, it returns the acyclic subgraph, which is then topologically sorted to return the total ordering T.
algorithm berger_shor() is input: graph G = (V, E) output: total ordering T G' <- G
scc <- strong_connect(G) remove scc edges from G' for component in sccs do new_component <- approximate(component) G' <- G' ∪ new_component end for return topological_sort(G') end
algorithm approximate is: input: graph G = (V, E)
output: acyclic graph G' = (V, E') G' <- G
order nodes in G based on preprocessing heuristic for each v in V do
if v.indegree > v.outdegree do A <- outgoing edges from v remove A from E B <- incoming edges to v G'.E' <- G'.E' ∪ B remove B from E else do A <- incoming edges to v remove A from E
B <- outgoing edges from v G'.E' <- G'.E' ∪ B remove B from E end if end for return G' end
3.4.2.3: Runtime Analysis
The Berger/Shor New 2-Approximation algorithm completes in greatly reduced time compared to the other algorithms implemented during this project. This algorithm visits every node within a given graph and determines the indegree and outdegree of that node, both operations which take O(1) time each. The smaller of the two sets of edges is discarded from the input graph, then the larger of the two sets of edges is copied to the final graph before being discarded from the input. Because edges are removed from the input graph in both cases at each iteration of the
algorithm, each edge is processed only once in the algorithm, resulting in O(E) for all edge computations. Thus, our overall runtime is O(2V) + O(E), or O(V + E) [1].