Professional Documents
Culture Documents
Yiannis Hadjiargyrou
Savvas Savvides
Table of Contents
TABLE OF CONTENTS..............................................................................2
1 INTRODUCTION................................................................................3
2 GETTING STARTED..........................................................................4
3 PROVE..................................................................................................4
7 TESTING.............................................................................................11
8 CONCLUSION:..................................................................................12
Suppose you are running a web site that is visited by the same set of people
every day. Each visitor claims membership in one or more demographic
groups; for example, a visitor might describe himself as male, 4050 years
old, a father, a resident of Paphos, an academic, a blogger, and a fan of
Michel Jackson. Your site is supported by advertisers. Each advertiser has
told you which demographic groups should see its advertisements and how
many of its advertisements you must show each day. Altogether, there are n
visitors, k demographic groups, and m advertisers.
Question: Describe an efficient algorithm to determine, given all the data
described in the previous paragraph, whether you can show each visitor
exactly one ad per day, so that every advertiser has its desired number of ads
displayed, and every ad is seen by someone. in an appropriate demographic
group.
Introduction
3 Prove
We now prove that this network enforces the constraints of the original
problem
Each visitor is seen exactly one ad per day.
This is guaranteed by the arcs (s,Di) of capacity 1.
The last proof cannot be guaranteed, as the number of ads that will show
commensurate with the number of visitors we have.
Example
If you have 6 visitors, we will show 6 ads since every visitor is see one ad
per day. So, if an advertiser want to show 8 ads per day this is impossible.
We have shown the network correctly models the problem of Customized
Advertisements in a web site. Hence, we conclude that a valid committee
exists precisely when the max flow of the constructed network has value n.
4 How to solve it
We do some search and analysis about the problem and we decide that we
need to do match function, then Breadth-first search (BFS) and at the end
max flow to resolve it.
First, we must say that our demographic groups are stable to become the
matching right. (see Figure 2)
Now at the beginning we ask the visitors about the details we need from
them (age, sex, interests and job) and then advertisers put the target group of
their ads and how many times they want to show each ad. Both of visitors
and advertisers we save them in 2D array for each one.
After we take the necessary information needed we apply a match function
to find with what demographic group every ad match base on the targets
give the advertiser. We store this matching to a text file. Then we insert the
elow we will analyse our code using pseudocode and an example with 5
visitor and 4 advertiser.
For every visitor base of the number of visitors we have we create a unique
id for each one. Then we ask them to tell as their age, sex, interests and job.
We save them in visitors array. The same procedure happens for the
advertisers.
Interest
Id Age Sex s Job
1 young male Sports student
femal bussines
2 young e Arts s
ID Demands
6 male, sport
7 young, student
8 adult, music
9 female, arts
Figure 4Example of advirtiser Table
No.
Display
1
2
2
0
Figure 5Desired number of ads displayed of each advertiser
Before max flow function run we read the values of the file. First
read the number of nodes and the number of edges.
fscanf(input,"%d %d",&no,&e);
Also we read each line separately from the file and store it as an 0
to 1 is equal to capacity 1 for example, until reach the number of
edges which means the end of the file.
for (i=source; i<number of edges(26); i++) {
fscanf(input,"%d %d %d",&a,&b,&c);
capacity [0][1] = 1;
}
Max flow algorithm with breadth-first search algorithm:
Let G (V, E) be a graph, and for each edge from u to v, let c (u, v)
be the capacity and f (u, v) be the flow. We want to find the
maximum flow from the source s to the sink t.
FordFulkerson
Inputs: Given a Network G= (V, E) with flow capacity c, a source
node s, and a sink node t
Output: Compute a flow f from s to t of maximum value
f (u, v) 0 for all edges (u, v)
While there is a path p from s to t in Gf, such that cf (u, v)>0 for
all edges (u, v) include in p (The path is founded by breadth-first
search algorithm which is explore the neighbor to determine an
augmenting path)
Find cf(p)=min {cf (u, v): (u, v)} include in p
For each edge (u, v) included in p
f (u, v) f (u, v) + c(p) (Send flow along the path)
When bfs cannot found more paths, s will not be able to t in the
residual network. If S is the set of nodes reachable by s in the
residual network, then the total capacity in the original network of
edges from S to the remainder of V is on the one hand equal to
the total flow we found from s to t and on the other hand serves
as an upper bound for all such flows. This proves that the flow we
found is maximal.
7 Testing
ID Demands
6 male, sport
7 Inputs:
young, student
8 adult, music
9 female, arts
Advertisers:
No.
Display
2
2
1
0
8 Conclusion:
In figure 7 we see the five feasible flow, also the max flow which is 5 hence,
we conclude that a valid committee exists precisely when the max flow of
the constructed network has value n(visitors).
Furthermore, we see that the number of adds which we display is satisfied
the number of how many of its ads each advertiser want to show each day.
Each visitor and advertiser is eligible to represent any group to which he has
an appointment and every ad is seen by someone in an appropriate
demographic group if you see in Figure 7 and if you compare it with the
inputs you will understand that we did.
And each visitor is displayed exactly one time in the results.