CS330 Homework 6
CS330 Homework 6
Graph: We can use maximal matching to solve the ergonomic problem. To build the
following graph that condenses the floor plan:
- Generate nodes ui ∈ U to represent the light switches and nodes wi ∈ W to represent the
light fixture.
- Connect (ui, wi) with an edge if the line drawn from ui to wi is not
intersected by any walls in the floor plan. Each edge has capacity of 1.
- Create 2 nodes starting node s and destination nodes. Connect s to all the
light switch nodes ui and all of the fixture nodes wi to t. Assign capacity of
1 to all these edges.
Run Algorithm: Run Ford-Fulkerson on the graph constructed as above, if the max flow
returned equals to n, then the floor plan is ergonomic, otherwise, return false.
Runtime analysis:
O(n3). To generate the graph, it takes O(n2) to fill in all the edges between lights
and switches, and generating the nodes has basic operation of O(1) for all the lights
and switches. Running the Ford-Fulkerson takes O(mC). Our setup of the graph allows
the maximum capacity of n, and there are, in the worst case, n2 edges between the
switch nodes and fixture nodes. Running the Ford-Fulkerson would takes O(n2) * O(n) =
O(n3), in the worst case scenario. The Algorithm, thus, takes O(n2) + O(n3) = O(n3).
Proof of correctness:
Proof by contradiction: Assume given a floor plan that is ergonomic and our return
value from the algorithm is false. Since, each switch send out only one unit of flow to the
fixture it is wired/connected to, it must be that the max flow is less than n (the capacity of of the
graph ≤ n) which means the graph is not saturated. It must be that some fixtures and switches
are not connected, because the fixtures and switches are not ergonomic to each other. The
algorithm will not return True unless all the fixture and switches are connected. Thus, there is a
contradiction in our assumption. Our construction of graph and evaluation of the return results
solves the problem correctly.
Algorithm:
Input: graph with a specific edge e with capacity deducted by 1
Output: max flow
Running time:
O(m+n) First, to identify whether e* is saturated we traverse through the max flow
path which takes O(m). The worst case is that we found out that e* is saturated, we
first look for a path from t to v and u from u to s, which is achievable if we
traverse the graph, and it takes O(m+n). Then, to finding an augmenting path to
redirect the 1 unit flow, we run one iteration of Ford-Fulkerson alg on the residual
graph, which is O(m+n). Thus, the total running time of our algorithm is O(m+n)
Running time:
The algorithm has two major parts, building the graph and running Ford-Fulkerson
- Building the graph would take O(m*n*k), generating nodes for the the
advertisers and the site visitors takes O(m) + O(n) times with base operation
of O(1). To fill in the edges, we need to traverse through all the users, then
for each user, we need to traverse through all the demographic groups, and
then traverse through all the advertisers to see if their contract includes
the current demographic group. Thus it take O(n)*O(k)*O(m) = O(nkm)
- Running Ford Fulkerson takes O(mC), which in the worst case of our graph would
be O(m*n) to go through all the edges. The maximum capacity coming out from
the source node s would be n, going to n number of site visitors, which would
be O(m*n)*O(n) = O(n2m)
Thus, if we assume that there are less demographic groups than there site visitors,
the running time of our algorithm comes down to O(n2m). Without such assumption, the
aggregate running time of our algorithm would be O(nmk) + O(n2m).
Proof of correctness:
Proof by contradiction: Assume that it is possible to arrange ads so that all the contracts are
satisfied and our algorithm returns false on the graph constructed as specified. This means that
the max flow returned by the Ford-Fulkerson is less than ∑ri . Because all the edges between
visitor and advertiser have flow value of 1, it must be that there are less than ∑ri number of
edges with the flow value 1 between the visitor and advertisers. This can only happen if the
number of site visitors does not match the ri for each of the advertisers. Thus, there is a
contradiction in our assumption. Conversely, if (max flow = ∑ri), there must be ∑ri constructed
between the advertisers and users. Therefore there is a flow value ∑ri which is the max flow
because it saturates the max capacity.
Consider a graph G = (V, E) where the vertices corresponds to the processes while the
edges corresponds to the resources. The requested resourced by a process would the be
edges connected to that process node. If two nodes are requesting the same resource,
then the edge would connect with two requesting process nodes. To solve the Resource
Reservation problem, we are just simply finding a independent set size of k. If there
is such a set, the k nodes in the set would give us processes that do not fight for
resources with each other.
Conversely, if we have a set of nodes that can be active at the same time.
Then there shouldn’t be any resource edge connecting these nodes. For any of the two
nodes in this set, if they are joint by an edge, then they are fighting for the same
resources, so they cannot be active at the same time and the set is not an
independent set for these two nodes connected by an edge.
Because we know that the independent set problem is NP-complete, we can say
that the Resource Reservation is also NP-complete.
Proof of correctness:
Proof by contradiction: As proved above any independent set of the graph would
represent the non conflicting set of processes. Suppose that we returned yes on a
graph that does not any any pair of non-conflicting nodes. Our algorithm traverses
all pairs of vertices and if they are independent of each other then we return these
two as the coexisting processes. Because these two processes have no edge connecting
the two, then it must be that they are not requesting the same resources, which is a
conflict with our assumption, thus the algorithm does find the non-conflicting pair
if there is one.
(c) The special case of the problem when there are two types of resources—say, people and
equipment—and each process requires at most one resource of each type.
In this problem, we redefine the graph so that the nodes are the resources for each
person and equipment, and the processes are the edges jointing the person nodes and
the equipment nodes. Then we are looking for a set of processes with non-conflicting
resources requirements, which means that the set of requests must not have the same
human and machine nodes as end point, which is then a bipartite matching.
Algorithm:
Input: set of human and machine resources and the process requests
Output: maximum bipartite matching
Graph:
- Generate nodes ui for all the people that the process can request and nodes wi
for all the machines resources
- Use edges of capacity 1 to represent processes to connect specific human to
machine resources that the same process request.
- Generate source node s and connect it to all the human resources with edges of
capacity 1 and destination node t and connect all of them from machine nodes
to t with edges of capacity 1.
Run Algorithm: Run Ford-Fulkerson on the above graph, and if max flow (f) ≥ k, return
True, else return False. This means that there are f number of maximum flow edges,
which are also the maximum bipartite matching for the graph. In our setup, these are
also the processes that can be satisfied at the same time.
Claim: Requests can be satisfied at the same time if and only if they are in the
maximum bipartite matching of the graph
If the max flow = f, then there are maximum of n edges in the bipartite
matching between the people and machine nodes. Because all edges in the graph have
capacity 1, only 1 unit of flow is being let into each human nodes. Thus, each
machine node would only have one valid edge coming in from only one of the human
nodes because only 1 unit of flow is being let out. Thus, the f edges are maximum
bipartite matching of the graph, which have different human and machine nodes as
endpoints. They are the maximum non-conflicting processes. Conversely, if there are n
numbers of non-conflicting processes, it means that there would be n number of
bipartite-matched edges from human nodes to the machine nodes. Our running of Ford-
Fulkerson would pick the maximum flow edges, which equivalents the maximum bipartite
matching in our setup of the graph.
Proof of correctness:
First, we need to prove that Ford-Fulkerson would give us maximum bipartite matching:
Proof by contradiction: Assume that the maximum flow returned by Ford-Fulkerson is
not a Bipartite matching given our graph construction. Because all edges in the graph
have capacity 1, and only 1 unit of flow is being let out of each machine node, each
machine node would only have one valid edge coming in from only one of the human
nodes because only 1 unit of flow is being let out. Thus, the all max flow edges
between human nodes and machine nodes must have distinct ends. Thus, we found
contradiction in our assumption, and Ford-Fulkerson would find maximum bipartite
matching in the graph.
Then, we need to prove that bipartite matching solves this case of the problem.
Proof by contradiction: Assume that our algorithm returns n number of max flow edges
and there are less than or more than n number of non-conflicting processes existing
in the system. If the maxflow = n, there must be maximum of n edges in the bipartite
matching between the people and machine nodes, which means there are maximum number
of n edges with different human and machine nodes as endpoints. Thus, there must be
maximum number of n non-conflicting processes, which forms a conflict with our
assumption. Conversely, if there are n numbers of non-conflicting processes, it means
that there would be n number of edges with flow value of 1 with different end points.
Our running of Ford-Fulkerson find the maximum amount of these edge. Thus, algorithm
is correct.
(d) The special case of the problem when each resource is requested by at most two processes.
Consider a case of the Resource Reservation problem, where each resource edge
now connect with up to 2 process nodes. If two nodes are requesting the same
resource, then the edge would connect the two requesting process nodes. To solve this
special case, we are finding a solution to the a general case resource reservation
problem by looking for an independent set size of k in the graph. Thus the special
case is a reduction of the Resource Reservation problem as we proved in part (a).
Thus, this special case is still an NP-Complete problem.
Question 5. Chapter 8. Exercise 10.
Given G, the paths {Pi}, and a number k, is it possible to place advertisements on at most k of
the nodes in G, so that each path Pi includes at least one node containing an advertisement, with
input G, {Pi : i = 1, . . . , t}, and k?
Checking whether at least one of k nodes lies on path Pi takes polynomial time O(kn),
and thus, we can check the entire graph G { pi: i = 1… t } whether the given set of k
nodes is a valid set for it with polynomial time O(t*kn).
Algorithm:
Inputs: G of {Pi} and k
Outputs: a set of at most k nodes
ALG(G, k) {
Initialize set T to maintain the set ready to be returned
If (k==1) {
For each nodes v
Check if it lies on all paths,
if yes return {v}, if not, return “no”
}
Else { // k > 1
If (S(G, k) == True)
For each nodes v {
G’ ← Delete v and all paths through v from G,
Input into S so see if the new input have a valid set of
ads of size at most k-1.
Because S would return true on all vertices in a valid
set, add qualifying node to U
}
Else
Return “no”
}
Return U;
}
Proof of Correctness:
Proof by induction:
Base case: k = 1, If all paths cross at one node, if yes, return such node, if not,
return “no such node”.
Inductive case: k > 1, we input the Graph into Algorithm S, if S returns “no” we
return no such set of nodes” as well, if the Alg S returns “yes”, we traverse all
nodes v of {V}, delete v and all paths through it and input the new Graph into S
along with k-1. If S returns “yes”, then we add this node into the set of nodes U
that we maintain to be returned by our algorithm. whether, on this new input, there
is a valid set of ads of size at most k-1. There will be at least one node v that S
will return “yes” on namingly this node would be the node that all paths go through,
because we have already tested if such a node exist with S(G, k) test. Because U-{v}
is a valid set of at most k-1 advertisements on the new input, S will return yes on
any v of U. After a valid node has been identified, the problem is reduced to a set
of at most k-1 advertisements. By induction, when our algorithm finished, we have a
complete set of nodes T of valid advertisement that is size of at most k.