Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Microsoft Word - Assignment 2.docx MATH7232 Operations Research & Mathematical Planning 2018 Assignment 2 – Integer Programming...

1 answer below »
Microsoft Word - Assignment 2.docx
MATH7232    Operations    Research    &    Mathematical    Planning    2018    
Assignment    2    –    Integer    Programming    
    
This    assignment    is    due    by    6pm    on    Friday,    April    27th    and    is    worth    20%    of    your    final    grade.    You    
can    do    each    assignment    in    pairs,    with    a    single    submission.    
    
Your    job    with    an    Operations    Research    consulting    company    is    going    well.        Your    boss    and    
client    would    like    you    to    continue    working    to    help    Pure    Fresh    improve    their    operations.    
Communications    to    you    from    the    company    will    be    provided    at    
https:
courses.smp.uq.edu.au/MATH7232    
The    first    communication    will    appear    before    5pm    on    Thursday,    March    29th    with    the    final    
communication    appearing    on    or    before    Friday,    April    20th.    
You    will    need    to    prepare    a    report    which    includes    two    main    sections:    
Section    A    –    Report    to    your    boss    
• A    general    mathematical    formulation    of    the    problem,    including    definitions    of    sets,    
data,    variables,    objective    function    and    constraints.        7    marks    
• A    Python    file    with    the    problem    modelled    for    Gurobi.    This    should    be    easy    to    relate    
ack    to    the    formulation.    Your    boss    will    attempt    to    execute    this    model.        5    marks    
Section    B    –    Report    to    the    client    
• Written    responses    that    clearly    and    concisely    address    the    needs    of    the    client    given    
through    the    communications.        5    marks    
• Brief    insights    into    the    solution,    such    as    identifying    key    constraints    or    explaining    
the    effects    on    costs    of    additional    constraints    provided    by    the    client.        3    marks    
Submit    your    report    and    Python    files    via    Blackboard,    using    PDF    for    the    report    (saved    from    
Word    or    created    in    LaTeX).        
Only    one    submission    per    pair    is    necessary    but    make    sure    both    names    are    clearly    shown    on    
your    report.    Each    student    will    receive    separate    data    from    the    client    but    a    pair    need    only    
consider    one    data    set    in    the    report.    
Grading    Criteria    
    
Section    A
Marks XXXXXXXXXX
Sets Inco
ect or missing
description of sets
Co
ectly
describes sets
Data Missing some or all
descriptions of data.
Co
ectly
describes all data
Variables Inco
ect or missing
description of variables
Co
ectly
describes
variables


Objective
function
Inco
ect or missing
description of objective
function
Co
ectly
describes
objective function


Constraints Missing many or all
descriptions of
constraints
Co
ectly
describes some
constraints
Co
ectly
describes most
constraints
Co
ectly describes
all constraints.
Python code There is no relationship
etween Python code
and mathematical
formulation
Python code
mostly matches
mathematical
formulation
Python code
clearly matches
mathematical
formulation
Execution Python code fails to run Python code runs
ut gives
inco
ect answer
Python code
uns and gives
co
ect answe
Comments Python code has few or
no comments
Python code is
clearly
commented


Section    B
Marks XXXXXXXXXX
Response to
communications
Fails to address any of
the client questions
Co
ectly
addresses one
client question
Co
ectly
addresses three
client questions
Co
ectly addresses
all client questions
Written response Poorly written response
with frequent e
ors in
grammar, spelling or
technical language;
and/or unnecessarily
long
Concisely
addresses needs
of client with few
e
ors in writing
Excellent
proficiency in
clearly and
concisely
addressing
needs of client
Insights into the
solution
Inco
ect or missing
insights into solution
Identifies some
important factors
that affect the
solution.
Identifies
important
factors that
affect the
solution
Provides insight and
thoroughness in
identifying factors
that affect the
solution
Answered Same Day Mar 30, 2020 MATH7232

Solution

Abr Writing answered on Apr 09 2020
135 Votes
Optimization.html


Importing Packages¶
In [1]:

import pandas as pd
import numpy as np
from gurobipy import *
import warnings
warnings.filterwarnings("ignore")
Data¶
In [2]:

nrows = 8
ncols = 3
init = [3200, 4000, 3800]
fileHandle = 'Demand.xlsx'
df = pd.read_excel(fileHandle)
df
Out[2]:
                Quarter        Brisbane        Melbourne        Adelaide        Cost
        0        Q1        1700        1950        2750        832
        1        Q2        2550        3000        2850        965
        2        Q3        2900        2400        1200        968
        3        Q4        2800        1600        2250        874
        4        Q5        1850        2200        2900        966
        5        Q6        2050        3200        1950        1007
        6        Q7        3300        3150        900        827
        7        Q8        2650        2150        1700        914
Variables¶
In [3]:

m = Model("mip1")
var = {}
for row in range(nrows):
for col in range(ncols):
name = str(row) + str(col)
var[name] = m.addVar(ub=10000, name=name)
var[name].vType = GRB.INTEGER

m.update()
In [4]:

idx = 0
for row in range(nrows):
for col in range(ncols):
name = str(row) + str(col)
colname = df.columns[col+1]
if idx-3 >= 0:
init.append(init[idx-3] + var[name] - df.iloc[row][colname])
idx += 1
else:
init[idx] = init[idx] + var[name] - df.iloc[row][colname]
idx += 1
Objective¶
In [5]:

obj = 0
idx = 0
for row in range(nrows):
for col in range(ncols):
name = str(row) + str(col)
colname = df.columns[col+1]
obj += var[name]*df.Cost[row] + init[idx]*35
idx += 1
m.setObjective(obj)
Constraints¶
In [6]:

contraint = 0
for row in range(nrows):
m.addConstr(var[str(row) + str(0)] + var[str(row) + str(1)] + var[str(row) + str(2)] <= 10000, "c"+str(contraint))
contraint += 1
idx = 0
for row in range(nrows):
for col in range(ncols):
name = str(row) + str(col)
colname = df.columns[col+1]
m.addConstr(init[idx] >= 0, "c"+str(contraint))
contraint += 1
idx += 1
Optimization¶
In [7]:

m.optimize()
for v in m.getVars():
print('%s %g' % (v.varName, v.x))
print('Obj: %g' % obj.getValue())
Optimize a model with 32 rows, 24 columns and 132 nonzeros
Variable types: 0 continuous, 24 integer (0 binary)
Coefficient statistics:
Matrix range [1e+00, 1e+00]
Objective range [9e+02, 1e+03]
Bounds range [1e+04, 1e+04]
RHS range [1e+03, 2e+04]
Found heuristic solution: objective 4.279545e+07
Presolve removed 3 rows and 0 columns
Presolve time: 0.00s
Presolved: 29 rows, 24 columns, 129 nonzeros
Variable types: 0 continuous, 24 integer (0 binary)
Root relaxation: objective 4.076690e+07, 19 iterations, 0.00 seconds
Nodes | Cu
ent Node | Objective Bounds | Work
Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
* 0 0 0 4.076690e+07 4.0767e+07 0.00% - 0s
Explored 0 nodes (19 simplex iterations) in 0.08 seconds
Thread count was 4 (of 4 available processors)
Solution count 2: 4.07669e+07 4.27955e+07
Optimal solution found (tolerance 1.00e-04)
Best objective 4.076690000000e+07, best bound 4.076690000000e+07, gap 0.0000%
00 3650
01 3350
02 3000
10 -0
11 -0
12 -0
20 300
21 -0
22 -0
30 5900
31 1850
32 2250
40 -0
41 5150
42 4850
50 800
51 -0
52 -0
60 3300
61 4100
62 2600
70 2650
71 1200
72 -0
Obj: 4.07669e+07
Result¶
In [8]:

db = df
for v in m.getVars():
row = int(list(str(v.varName))[0])
col = int(list(str(v.varName))[1])
colname = db.columns[col+1]
db[colname][row] = v.x

d
Out[8]:
                Quarter        Brisbane        Melbourne        Adelaide        Cost
        0        Q1        3650        3350        3000        832
        1        Q2        0        0        0        965
        2        Q3        300        0        0        968
        3        Q4        5900        1850        2250        874
        4        Q5        0        5150        4850        966
        5        Q6        800        0        0        1007
        6        Q7        3300        4100        2600        827
        7        Q8        2650        1200        0        914
Boss.docx
Importing Packages
import pandas as pd
import numpy as np
from gurobipy import *
import warnings
warnings.filterwarnings("ignore")
Data
nrows = 8
ncols = 3
init = [3200, 4000, 3800]
fileHandle = 'Demand.xlsx'
df = pd.read_excel(fileHandle)
df
        
        Quarte
        Brisbane
        Melbourne
        Adelaide
        Cost
        0
        Q1
        1700
        1950
        2750
        832
        1
        Q2
        2550
        3000
        2850
        965
        2
        Q3
        2900
        2400
        1200
        968
        3
        Q4
        2800
        1600
        2250
        874
        4
        Q5
        1850
        2200
        2900
        966
        5
        Q6
        2050
        3200
        1950
        1007
        6
        Q7
        3300
        3150
        900
        827
        7
        Q8
        2650
        2150
        1700
        914
Variables¶
Defining the variables. There are in total 24 (3 X 8) variables as there are 3 cities and 8 quarters.
m = Model("mip1")
var = {} for row in range(nrows):
for col in range(ncols):
name = str(row) + str(col)
var[name] = m.addVar(ub=10000, name=name)
var[name].vType = GRB.INTEGER
m.update()
Defining the number of ba
els left at every city at the end of every quarter.
idx = 0
for row in range(nrows):
for col in range(ncols):
name = str(row) + str(col)
colname = df.columns[col+1]
if idx-3 >= 0:
init.append(init[idx-3] + var[name] - df.iloc[row][colname])
idx += 1
else:
init[idx] = init[idx] + var[name] - df.iloc[row][colname]
idx += 1
Objective
Objective is to minimize the total cost of buying new ba
els and concentrating the existing ones with a summation over every city and every quarter.
obj = 0
idx = 0
for row in range(nrows):
for col in range(ncols):
name = str(row) + str(col)
colname = df.columns[col+1]
obj += var[name]*df.Cost[row] + init[idx]*35
idx += 1
m.setObjective(obj)
Constraints
There are two types of constraints:
1. Total number of ba
els imported in any quarter (sum over all the cities) should be less than, equal to 10000.
2. The number of ba
els left after any quarter in any city should be greater than or equal to zero.
constraint = 0
for row in range(nrows):
m.addConstr(var[str(row) + str(0)] + var[str(row) + str(1)] + var[str(row) + str(2)] <= 10000, "c"+str(constraint))
constraint += 1
idx = 0
for row in range(nrows):
for col in range(ncols):
name = str(row) + str(col)
colname = df.columns[col+1]
m.addConstr(init[idx] >= 0, "c"+str(constraint))
constraint += 1
idx += 1
Optimization¶
m.optimize()
for v in m.getVars():
print('%s %g' % (v.varName, v.x)
print('Obj: %g' % obj.getValue())
Optimize a model with 32 rows, 24 columns and 132 nonzeros
Variable types: 0 continuous, 24 integer (0 binary)
Coefficient statistics:
Matrix range [1e+00, 1e+00]
Objective range [9e+02, 1e+03]
Bounds range [1e+04, 1e+04]
RHS range [1e+03, 2e+04]
Found heuristic solution: objective 4.279545e+07
Presolve removed 3 rows and 0 columns
Presolve time: 0.00s
Presolved: 29 rows, 24 columns, 129 nonzeros
Variable types: 0 continuous, 24 integer (0 binary)
Root relaxation: objective 4.076690e+07, 19 iterations, 0.00 seconds
Nodes | Cu
ent Node | Objective Bounds | ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here