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

Microsoft Word - Assignment 3.docx MATH7232 Operations Research & Mathematical Planning 2018 Assignment 3 – Dynamic Programming...

1 answer below »
Microsoft Word - Assignment 3.docx
MATH7232    Operations    Research    &    Mathematical    Planning    2018    
Assignment    3    –    Dynamic    Programming    
    
This    assignment    is    due    by    6pm    on    Friday,    May    25th    and    is    worth    10%    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    and    
that    of    their    customers,    including    the    corner    store    Jenny’s    Juices.    Communications    to    you    
from    the    company    will    be    provided    at    
https:
courses.smp.uq.edu.au/MATH7232    
The    first    communication    is    already    available    with    the    final    communication    appearing    on    
or    before    Friday,    May    11th.    
You    will    need    to    prepare    a    report    which    includes    two    main    sections:    
Section    A    –    Report    to    your    boss    
• A    general    formulation    that    describes    the    data,    stages,    states,    actions    and    the    
transition    and    value    functions    used    in    your    two    models.        8    marks    
• A    single    Python    file    with    your    implementations.    This    should    be    easy    to    relate    back    
to    the    formulation.    Your    boss    will    attempt    to    execute    this    model.        6    marks    
Section    B    –    Report    to    the    client    
• Written    responses    that    clearly    and    concisely    address    the    needs    of    the    client    given    
through    the    communications.        6    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 0 1 2
Data Missing some or all descriptions of data
Co
ectly describes all data
Stages Missing clear description of stages
Co
ectly describes stages
States Inco
ect or missing description of states
Co
ectly describes state
for one communication
Co
ectly describes states
for all communications
Actions Inco
ect or missing description of actions
Co
ectly describes actions
for one communication
Co
ectly describes actions
for all communications
Value function
Inco
ect or missing
description of value
functions
Co
ectly describes value
function for one
communication
Co
ectly describes value
functions for all
communications
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 but gives inco
ect answer
Python code runs and gives
co
ect answer
Efficiency Python implementation is slow to run
Python implementation is
efficient
Utility
Difficult to determine
optimal strategy from
Python implementation
Easy to determine optimal
strategy from Python
implementation
Section B
Marks 0 1 2
Response to
communications
Fails to address any of the
client questions
Co
ectly addresses one
client question
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
Strategies
Poor or missing description
of optimal strategies for
stochastic models
Good description of optimal
strategies for stochastic
models
Clear and insightful
description of optimal
strategies for stochastic
models
Answered Same Day May 16, 2020 MATH7232

Solution

Abr Writing answered on May 23 2020
134 Votes
Pure Fresh.html


Importing Packages¶
In [1]:

import numpy as np
import pandas as pd
Importing Demand data¶
In [2]:

df = pd.read_excel('demand.xlsx', index_col = 0)
demand = df.iloc[0].tolist()
df
Out[2]:
                1        2        3        4        5        6        7
        Day                                                        
        Demand        6        8        4        11        5        7        11
Variables¶
orders everyday should be between 0 to 15 bottles
In [3]:

orders = np.zeros(df.shape[1])
Defining the profit function
In [4]:

def profit(initial, demand, order):
'''
where:
initial is the amount of bottles available in the fridge from previous days: between 0 and 10
demand is the daily demand of bottles
order is the amount of bottles ordered a day before for selling: between 0 to 15
'''
if order == 0:
# No order, no fixed cost
return min([initial+order, demand])*(5 - 1.5)
else:
# As there is a fixed cost of $10 per delivery, therefore:
return min([initial+order, demand])*(5 - 1.5) - 10
Storing the profits for all possible values of variables: initial, demand and orde
In [5]:

# Creating an empty Dataframe
columns = ['Profit']
ows = (1+10)*(len(np.unique(demand)))*(1+15)
profitdb = pd.DataFrame(columns = columns, index = range(rows))
idx = 0
newIndex = list()
# Looping for every variable
for init in range(1+10):
for dmnd in np.unique(demand):
for ordr in range(1+15):
profitdb.iloc[idx] = [profit(init, dmnd, ordr)]
index = str(init) + '.' + str(dmnd) + '.' + str(ordr)
newIndex.append(index)
idx += 1
profitdb.index = newIndex
profitdb.to_csv('profit.csv')
Constraints¶
Anything left after Day 7 will be wasted. Therefore:
order.sum()
where, demand.sum() = 52
Objective¶
Each deliveries cost $10 extra so we have to keep the number of orders/deliveries as low as possible to increase the overall profit
In [6]:

# Creating a tree class
class Tree(object):
def __init__(self):
# name for the name of the node can be defined as day.initial.demand.orde
self.name = None
self.childrens = list()
self.parents = list()
self.path = list()

def setProfit(self):
temp = self.name.split('.')
init = int(temp[1])
demand = int(temp[2])
order = int(temp[3])
self.profit = profit(init, demand, order)
In [7]:

def find2numbers(sm):
'''
The function is used to find all the combinations of initial bottles and the order to be placed
to satisfy the orde
'''
result = []
for initial in range(min([10, sm])+1):
for order in range(min([sm+1, 15+1])):
if initial+order == sm:
result.append([initial, order])
return result
In [8]:

# Creating a tree for the problem
nodesAll = []
day7nodes = []
# Day 7
day = 7
for combination in find2numbers(demand[day-1]):
init = combination[0]
order = combination[1]
name = str(day) + '.' + str(init) + '.' + str(demand[day-1]) + '.' + str(order)
node = Tree()
node.name = name
node.setProfit()
day7nodes.append(node)
nodesAll.append(node)
In [9]:

# Day 6 to 1
nodes = day7nodes
for day in range(6, 0, -1):
nodesTemp = []
for nde in nodes:
temp = nde.name
temp = temp.split('.')
initTemp = int(temp[1])
for combination in find2numbers(initTemp+demand[day-1]):
init = combination[0]
order = combination[1]
name = str(day) + '.' + str(init) + '.' + str(demand[day-1]) + '.' + str(order)
node = Tree()
node.name = name
node.setProfit()
nde.parents.append(node)
node.childrens.append(nde)
nodesTemp.append(node)
nodesAll.append(node)
nodes = nodesTemp
In [10]:

maxNode = None
maxProfit = 0
for node in nodesAll:
order = node.name.split('.')[3]
node.path.append(order)
bestChild = None
best = 0
for child in node.childrens:
if child.profit > best:
best = child.profit
bestChild = child
if bestChild is not None:
node.profit += best
node.path += bestChild.path
if node.profit > maxProfit:
maxProfit = node.profit
maxNode = node
maxNode.path.reverse()
Results¶
In [11]:

df.loc['Order'] = maxNode.path[:7]
df
Out[11]:
                1        2        3        4        5        6        7
        Day                                                        
        Demand        6        8        4        11        5        7        11
        Order        11        7        0        15        0        13        0
In [12]:

print('The maximum weekly profit for the Juice shop is: ${}'.format(maxProfit))
The maximum weekly profit for the Juice shop is:...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here