1
00:00:18,060 --> 00:00:26,259
in this class we will look at two formulations
the maximum flow problem and the bin packing
2
00:00:26,259 --> 00:00:34,940
problem so our formulation seven is the maximum
flow problem we are given a network and we
3
00:00:34,940 --> 00:00:42,670
want to find out the maximum flow in the given
network the arc capacities are given in the
4
00:00:42,670 --> 00:00:51,670
network so this is the network that we are
going to consider this network has five nodes
5
00:00:51,670 --> 00:01:01,619
or vertices these are the nodes and the network
has arcs connecting these nodes so these are
6
00:01:01,619 --> 00:01:09,380
this arc from one two two these arcs are represented
as i j and they go from i to j for example
7
00:01:09,380 --> 00:01:17,259
one two one two three two two three and so
on this network is a director which means
8
00:01:17,259 --> 00:01:23,490
arcs are given directions
now these arcs have capacities we want to
9
00:01:23,490 --> 00:01:30,970
find out the maximum flow that can be sent
through this network which means we will assume
10
00:01:30,970 --> 00:01:38,749
that these points one and five will act as
some kind of a source and destination now
11
00:01:38,749 --> 00:01:45,630
one is called the source five is called the
destination sometimes five is also called
12
00:01:45,630 --> 00:01:55,359
the sink so some commodity or some fluid is
flowing from one to five along these arcs
13
00:01:55,359 --> 00:02:06,630
which act like pipes the arc capacity is equivalent
of what can flow in this arc so with this
14
00:02:06,630 --> 00:02:13,030
we start defining the formulation for the
maximum flow problem
15
00:02:13,030 --> 00:02:22,040
so let x i j be the amount of flow in the
arc from i to j so there are many arcs so
16
00:02:22,040 --> 00:02:28,069
there is an arc from one to two therefore
there is a x one two there is an arc from
17
00:02:28,069 --> 00:02:35,180
one to three therefore there is a x one three
there is no arc connecting one and four so
18
00:02:35,180 --> 00:02:41,790
there is no x one four so we will have as
many variable as the number of arcs in this
19
00:02:41,790 --> 00:02:52,680
network so let x i j be the flow in the arc
i j or the arc that connects nodes i and j
20
00:02:52,680 --> 00:03:00,450
we also define f as the flow in the network
which we try to maximize now let us write
21
00:03:00,450 --> 00:03:09,030
the objective function and the constraints
for this problem
22
00:03:09,030 --> 00:03:16,860
so we want to maximize the flow in this network
so the flow in this network is f so we want
23
00:03:16,860 --> 00:03:25,090
to maximize f so maximizing f is the objective
function f is the variable that represents
24
00:03:25,090 --> 00:03:32,659
the flow now what is the flow the flow is
something that flows out of the source or
25
00:03:32,659 --> 00:03:40,459
the flow is the same as that which flows into
the sink or destination so let us consider
26
00:03:40,459 --> 00:03:49,709
vertex one or node one which acts as the source
so what goes out of one is x one two plus
27
00:03:49,709 --> 00:03:58,269
x one three so x one two plus x one three
goes out of one and that represents the flow
28
00:03:58,269 --> 00:04:05,370
so the first constraint which is for node
one is x one two plus x one three is equal
29
00:04:05,370 --> 00:04:14,950
to f f is the flow so whatever flows is equal
to x one two plus x one three
30
00:04:14,950 --> 00:04:20,959
now if we look at the sink or the destination
which is five now we can look at the fifth
31
00:04:20,959 --> 00:04:30,500
constraint now what enters the sink is x two
five plus x four five plus x three five and
32
00:04:30,500 --> 00:04:38,960
the same flow that went out of one will have
to reach five so the constraint for five or
33
00:04:38,960 --> 00:04:47,750
destination or sink is given by x two five
plus x three five plus x four five is again
34
00:04:47,750 --> 00:04:56,180
equal to f x two five is coming this way x
three five is coming here x four five is coming
35
00:04:56,180 --> 00:05:05,090
here now the remaining three vertices which
are two three and four act as intermediate
36
00:05:05,090 --> 00:05:13,710
vertices so if i look at node two or vertex
two whatever comes in to node two will have
37
00:05:13,710 --> 00:05:21,800
to leave node two so x one two is the flow
coming into node two and the flow that leaves
38
00:05:21,800 --> 00:05:30,430
node two are x two three x two four and x
two five so the constraint will be x one two
39
00:05:30,430 --> 00:05:37,490
should be equal to x two three plus x two
four plus x two five and that is shown as
40
00:05:37,490 --> 00:05:45,210
this constraint which says minus x one two
plus x two three plus x two four plus x two
41
00:05:45,210 --> 00:05:53,270
five equal to zero which is the same as x
one two is equal to x two three plus x two
42
00:05:53,270 --> 00:06:00,240
four plus x two four plus x two five
similarly looking at node three whatever comes
43
00:06:00,240 --> 00:06:07,970
into three has to leave three so what comes
into three is x one three plus x two three
44
00:06:07,970 --> 00:06:14,950
so the flow that enters node three is x one
three plus x two three the flow that leaves
45
00:06:14,950 --> 00:06:23,020
node three is x three four plus x three five
therefore x one three plus x two three should
46
00:06:23,020 --> 00:06:30,330
be equal to x three four plus x three five
which is written as minus x one three minus
47
00:06:30,330 --> 00:06:38,870
x two three plus x three four plus x three
five equal to zero similarly for node four
48
00:06:38,870 --> 00:06:45,860
whatever comes into node four should be equal
to what leaves node four so x two four plus
49
00:06:45,860 --> 00:06:53,120
x three four is equal to x four five which
is written as minus x two four minus x three
50
00:06:53,120 --> 00:06:59,509
four plus x four five equal to zero
so there are five constraints corresponding
51
00:06:59,509 --> 00:07:07,940
to each of these nodes the constraints corresponding
to the source and the sink have the flow variable
52
00:07:07,940 --> 00:07:15,640
the other constraints corresponding to the
intermediate nodes do not have the flow variable
53
00:07:15,640 --> 00:07:22,889
and whatever comes in to that node leave that
node or vertex so five constraints are written
54
00:07:22,889 --> 00:07:31,610
now in addition to these we have the capacity
restrictions on the arcs now x one two is
55
00:07:31,610 --> 00:07:39,080
the flow in the arc connecting one and two
and that cannot exceed twenty units therefore
56
00:07:39,080 --> 00:07:45,830
x one two is less than or equal to twenty
similarly x one three is less than or equal
57
00:07:45,830 --> 00:07:52,949
to forty and so on so there are eight arcs
and we have eight capacity constraints which
58
00:07:52,949 --> 00:08:01,159
are given here in addition the non negativity
constraints f and x i j are greater than or
59
00:08:01,159 --> 00:08:08,419
equal to zero so this completes the formulation
of the maximum flow problem the objective
60
00:08:08,419 --> 00:08:15,710
is to maximize the flow the flow is given
by f there are five constraints one for each
61
00:08:15,710 --> 00:08:24,330
node or one for each vertex and these are
generally called as flow balance constraints
62
00:08:24,330 --> 00:08:31,389
they are built on the principle that for every
node whatever comes in has to go out now if
63
00:08:31,389 --> 00:08:38,250
we assume that f comes into one then f will
be equal to x one two plus x one three
64
00:08:38,250 --> 00:08:45,390
similarly if f goes out of node five then
f will be equal to x two five plus x three
65
00:08:45,390 --> 00:08:53,160
five plus x four five we also have the arc
capacity constraints there are as many constraints
66
00:08:53,160 --> 00:08:59,830
as the number of arcs and the non negativity
restriction so the number of variables is
67
00:08:59,830 --> 00:09:06,940
equal to the number of arcs plus one the one
is for the flow variable the number of constraints
68
00:09:06,940 --> 00:09:15,510
is equal to the number of nodes or vertices
plus the number of arcs now we make a minor
69
00:09:15,510 --> 00:09:23,470
change in this formulation and that is shown
here for example we can eliminate this f variable
70
00:09:23,470 --> 00:09:31,000
now we have use this f explicitly as a variable
that denotes the flow and we now know that
71
00:09:31,000 --> 00:09:37,010
this flow is equaled x one two plus x one
two three and the same flow is also equal
72
00:09:37,010 --> 00:09:44,940
to x two five plus x three five plus x four
five so we can replace this f as maximize
73
00:09:44,940 --> 00:09:51,620
x two five plus x three five plus x four five
and then we can write the constraints for
74
00:09:51,620 --> 00:09:59,120
the nodes two three and four and so on so
this way we will reduce the number of variables
75
00:09:59,120 --> 00:10:07,480
by one and we also reduce the two constraints
corresponding to the flow so ah but we retain
76
00:10:07,480 --> 00:10:14,500
the arc capacity restrictions
so the new formulation will not have the f
77
00:10:14,500 --> 00:10:23,329
variable it will have only the x i j variables
so it will have as many constraints as the
78
00:10:23,329 --> 00:10:30,860
number of arcs which are the arc capacity
constraints with respect to the flow conservation
79
00:10:30,860 --> 00:10:39,180
equations we will use one of them as the objective
function we will not necessarily use the other
80
00:10:39,180 --> 00:10:46,139
the other three for the intermediate nodes
are actually sufficient so this formulation
81
00:10:46,139 --> 00:10:52,970
will have as many variables as the number
of arcs it will have as many constraints as
82
00:10:52,970 --> 00:11:00,120
the number of arcs which are the flow conservation
or the capacity constraints and with respect
83
00:11:00,120 --> 00:11:05,440
to flow conservation we will have as many
constraints as the number of intermediate
84
00:11:05,440 --> 00:11:13,060
nodes we could either use the formulation
that explicitly has f and there is a pattern
85
00:11:13,060 --> 00:11:21,019
there the first way by which be formulated
has x i j and f it has an extra variable which
86
00:11:21,019 --> 00:11:29,490
is f it has as many constraints as the number
of nodes plus as many constraints as the number
87
00:11:29,490 --> 00:11:36,810
of arcs we could use either of the formulation
but the second one where we have eliminated
88
00:11:36,810 --> 00:11:45,500
the flow variable has one variable less so
this is how we formulate the maximum flow
89
00:11:45,500 --> 00:11:50,000
problem
and we now move on to another formulation
90
00:11:50,000 --> 00:11:55,570
which is called the bin packing problem it's
also called the one dimensional bin packing
91
00:11:55,570 --> 00:12:02,820
problem so let me introduce the problem in
a slightly different way now you are given
92
00:12:02,820 --> 00:12:12,079
eight numbers and these numbers are eight
six nine twenty eight seventeen twenty four
93
00:12:12,079 --> 00:12:20,519
seven and twenty one now the problem is to
make minimum number of groups such that the
94
00:12:20,519 --> 00:12:28,170
sum of the numbers in each group does not
exceed forty five or does not exceed a given
95
00:12:28,170 --> 00:12:37,889
number so this is a grouping problem now we
have to form minimum number of groups such
96
00:12:37,889 --> 00:12:45,279
that the sum of the elements or numbers in
each group does not exceed forty five it's
97
00:12:45,279 --> 00:12:52,040
fairly obvious that we eight groups we can
easily have a solution to this problem but
98
00:12:52,040 --> 00:12:57,100
the real challenge is what is the minimum
number of groups and which number goes to
99
00:12:57,100 --> 00:13:03,519
which group such that the sum of elements
in any group is less than or equal to forty
100
00:13:03,519 --> 00:13:10,279
five it is called a bin packing problem it's
called a one dimensional bin packing because
101
00:13:10,279 --> 00:13:15,019
these eight numbers that i have given here
can be treated as eight lengths
102
00:13:15,019 --> 00:13:23,100
so you could imagine sum eight sticks of certain
length lengths are eight six nine twenty eight
103
00:13:23,100 --> 00:13:31,079
and so on and then you want to put them into
a bag in a one dimensional way and the bag
104
00:13:31,079 --> 00:13:37,699
or the bin as it is called has a height of
forty five so when i put it in a one dimensional
105
00:13:37,699 --> 00:13:44,649
way i won't be able to put for example nine
plus twenty eight plus seventeen into a bin
106
00:13:44,649 --> 00:13:51,480
of forty five because it exceeds the bin length
so in general the bin length is given so in
107
00:13:51,480 --> 00:13:57,880
this example the bin length is forty five
i want to pack these items or length into
108
00:13:57,880 --> 00:14:04,470
bins in a one dimensional way such that i
use minimum number of bins and i am able to
109
00:14:04,470 --> 00:14:11,139
pack all these lengths or items therefore
it's called a bin packing problem its also
110
00:14:11,139 --> 00:14:16,399
called a one dimensional bin packing because
we are packing the bin in one dimension which
111
00:14:16,399 --> 00:14:22,889
means whatever you put in the bin we have
to add the lengths which is the same as grouping
112
00:14:22,889 --> 00:14:28,320
them and finding out the sum of the elements
in the group and that sum of elements in the
113
00:14:28,320 --> 00:14:35,089
group should not exceed the predefined number
which is forty five so let's try and formulate
114
00:14:35,089 --> 00:14:40,130
this problem
now maximum of eight groups are possible so
115
00:14:40,130 --> 00:14:49,589
we first say let y j be equal to one if group
is formed and y j equal to zero if group j
116
00:14:49,589 --> 00:14:59,610
is not formed we also define x i j equal to
one if the i'th number goes to group j and
117
00:14:59,610 --> 00:15:08,860
x i j equal to zero if the i'th number does
not go to group j the first significant difference
118
00:15:08,860 --> 00:15:16,120
is that the variables are not continuous variables
and these variables take only binary values
119
00:15:16,120 --> 00:15:25,630
and these variables take only values zero
or one now y j is one if group j is formed
120
00:15:25,630 --> 00:15:31,930
y j is zero if group j is not formed for example
if we don't have to form an eighth group then
121
00:15:31,930 --> 00:15:39,680
y eight will be zero if we have to form the
second group then y two will be equal to one
122
00:15:39,680 --> 00:15:47,000
for example if the first number eight goes
to the first group then x one one is equal
123
00:15:47,000 --> 00:15:56,470
to one and if it does not go it will be zero
so we have in this formulation eight variables
124
00:15:56,470 --> 00:16:05,899
for y z and sixty four variables for x i j
because each number can go to any one of the
125
00:16:05,899 --> 00:16:11,149
eight groups so there are sixty four binary
variables in this formulation
126
00:16:11,149 --> 00:16:18,120
now the objective function will be to minimize
the number of group that we form so minimize
127
00:16:18,120 --> 00:16:25,509
sigma y j which is minimize y one plus y two
plus y three plus y four upto y eight if we
128
00:16:25,509 --> 00:16:30,889
have to form eight groups then all the eight
variables will take value one if we have to
129
00:16:30,889 --> 00:16:38,069
form three groups then three out of the eight
will take value one so minimize sigma y j
130
00:16:38,069 --> 00:16:48,600
is the objective function now the constraints
are if i take any one of the words for example
131
00:16:48,600 --> 00:16:57,870
the the the number eight as the first number
then this number or this element or this item
132
00:16:57,870 --> 00:17:05,480
should go to only one of the bins now at the
moment we are considering eight possible bins
133
00:17:05,480 --> 00:17:12,920
so x one one plus x one two plus x one three
upto x one eight equal to one means the first
134
00:17:12,920 --> 00:17:20,199
subscript one which is the first number one
the first number which is eight will either
135
00:17:20,199 --> 00:17:25,320
go to the first group or the second group
or the third group or the fourth group or
136
00:17:25,320 --> 00:17:31,220
upto the eighth group but i'll go to only
one out of these eight groups so sigma x i
137
00:17:31,220 --> 00:17:39,790
j equal to one summed over j for every i so
there are eight constraints like this for
138
00:17:39,790 --> 00:17:46,230
the second number the constraint will look
like x two one plus x two two plus x two three
139
00:17:46,230 --> 00:17:52,780
plus x two four plus x tow five plus x two
six plus x two seven plus x two eight equal
140
00:17:52,780 --> 00:17:58,140
to one so like that for each of the eight
numbers there will be a constraint and there'll
141
00:17:58,140 --> 00:18:04,460
be eight constraints here so for every i there
are eight numbers there are eight constraints
142
00:18:04,460 --> 00:18:11,400
summed over j x i j equal to one each number
goes to only one out of the eight possible
143
00:18:11,400 --> 00:18:17,160
groups
now group that is formed should have a total
144
00:18:17,160 --> 00:18:23,420
less than or equal to forty five so if i am
forming the first group then y one is equal
145
00:18:23,420 --> 00:18:30,300
to one so the right hand side becomes forty
five so whatever goes into the first group
146
00:18:30,300 --> 00:18:34,180
which means if the first element goes then
it is going to take away eight out of the
147
00:18:34,180 --> 00:18:39,190
forty five if the second number goes it's
going to use up six out of the forty five
148
00:18:39,190 --> 00:18:45,340
so eight x one one plus six x two one plus
nine x three one plus twenty eight x four
149
00:18:45,340 --> 00:18:52,430
one etcetera is whatever goes into the first
group and if he first group is formed then
150
00:18:52,430 --> 00:18:57,200
whatever goes into the first group the sum
should be less than or equal to forty five
151
00:18:57,200 --> 00:19:03,900
if the eighth group is not formed then y eight
will become zero so the right hand side will
152
00:19:03,900 --> 00:19:08,790
become zero and no number will go to the eighth
group
153
00:19:08,790 --> 00:19:18,080
so sigma over i a a i x i j is less than or
equal to b y j is a very general way of representing
154
00:19:18,080 --> 00:19:24,380
two things if a group is formed then whatever
goes into that group should be less than or
155
00:19:24,380 --> 00:19:28,670
equal to forty five some of those elements
should be less than equal to forty five if
156
00:19:28,670 --> 00:19:35,090
the group is not formed then nothing goes
into that group so this is the way by which
157
00:19:35,090 --> 00:19:43,180
we formulate so there are seventy two variables
sixty four for the x i j variables and eight
158
00:19:43,180 --> 00:19:49,690
it for the y j variables seventy two variables
and there are eight plus eight sixteen constraints
159
00:19:49,690 --> 00:19:55,960
which are here this is for every element should
go to one group this is for every group when
160
00:19:55,960 --> 00:20:02,860
it is formed will have elements such that
the sum is less than or equal to forty five
161
00:20:02,860 --> 00:20:08,840
so this formulation has seventy two variables
and sixteen constraints all the variables
162
00:20:08,840 --> 00:20:15,480
are binary variables now let us do a little
bit into this problem let us make a simple
163
00:20:15,480 --> 00:20:22,180
solution by looking at these numbers and start
putting these numbers into groups so i as
164
00:20:22,180 --> 00:20:28,190
i start putting these numbers into groups
i realize that eight six and nine can go to
165
00:20:28,190 --> 00:20:33,950
the first group because if i had twenty eight
it exceeds the forty five so twenty eight
166
00:20:33,950 --> 00:20:38,980
and seventeen will go to the second group
twenty four and seven will go to the third
167
00:20:38,980 --> 00:20:46,170
group and twenty one will be the fourth group
so i a able to get a solution with four groups
168
00:20:46,170 --> 00:20:53,010
so i use this idea so now i can reduce the
y j variables to four and not eight in the
169
00:20:53,010 --> 00:20:58,910
earlier formulation i had eight possible groups
now i have a solution with four groups now
170
00:20:58,910 --> 00:21:05,540
i want to check is their solution with three
groups so i reduce the y variables to four
171
00:21:05,540 --> 00:21:10,940
and allot the numbers only to four groups
while we minimize the number of groups and
172
00:21:10,940 --> 00:21:17,340
now such a formulation will have eight into
four plus four thirty six variables it will
173
00:21:17,340 --> 00:21:23,330
have only y one plus y two plus y three plus
y four as the objective function it will have
174
00:21:23,330 --> 00:21:28,400
only twelve constraints and it is a simpler
formulation
175
00:21:28,400 --> 00:21:34,000
we can even go one step ahead and say that
i already have a solution with four groups
176
00:21:34,000 --> 00:21:40,630
now do i have a solution with three groups
so now i restrict y only to y one y two and
177
00:21:40,630 --> 00:21:46,910
y three which means the number of variables
comes down to twenty seven variables and eleven
178
00:21:46,910 --> 00:21:53,260
constraints so this is a type of a problem
where if we start with the solution to the
179
00:21:53,260 --> 00:22:03,380
problem i can get a more efficient formulation
so the bin packing formulation now has explained
180
00:22:03,380 --> 00:22:09,160
a few things now for the first time we have
seen a problem in which our variables are
181
00:22:09,160 --> 00:22:17,870
not continuous variables they are binary variables
so this formulation is a binary integer programming
182
00:22:17,870 --> 00:22:23,950
formulation and it is not a linear programming
formulation so we have used the bin packing
183
00:22:23,950 --> 00:22:32,300
to explain a binary integer programming formulation
and not a linear programming formulation second
184
00:22:32,300 --> 00:22:38,610
thing that we learn is that this is a type
of a problem where we could start with the
185
00:22:38,610 --> 00:22:44,840
solution and if we start with the solution
we can actually make the formulation simpler
186
00:22:44,840 --> 00:22:53,240
by defining fewer variables and fewer constraints
so with this we come to the end of the first
187
00:22:53,240 --> 00:23:02,420
module of this course which is linear programming
formulation in the subsequent module we will
188
00:23:02,420 --> 00:23:09,060
look at solving linear programming problems
and we will look at that in the next class