Microsoft Word - Assignment 3.docx MATH7232OperationsResearch&MathematicalPlanning2018 Assignment3–DynamicProgramming...

1 answer below »
this assignment is a combination of phython coding and operational research. please do the coding in phython 2.7 or 3.5 and do in gurobi and anaconda


Microsoft Word - Assignment 3.docx MATH7232OperationsResearch&MathematicalPlanning2018 Assignment3–DynamicProgramming Thisassignmentisdueby6pmonFriday,May25thandisworth10%ofyourfinalgrade.You candoeachassignmentinpairs,withasinglesubmission. YourjobwithanOperationsResearchconsultingcompanyisgoingwell.Yourbossand clientwouldlikeyoutocontinueworkingtohelpPureFreshimprovetheiroperationsand thatoftheircustomers,includingthecornerstoreJenny’sJuices.Communicationstoyou fromthecompanywillbeprovidedat https://courses.smp.uq.edu.au/MATH7232 Thefirstcommunicationisalreadyavailablewiththefinalcommunicationappearingon orbeforeFriday,May11th. Youwillneedtoprepareareportwhichincludestwomainsections: SectionA–Reporttoyourboss • Ageneralformulationthatdescribesthedata,stages,states,actionsandthe transitionandvaluefunctionsusedinyourtwomodels.8marks • AsinglePythonfilewithyourimplementations.Thisshouldbeeasytorelateback totheformulation.Yourbosswillattempttoexecutethismodel.6marks SectionB–Reporttotheclient • Writtenresponsesthatclearlyandconciselyaddresstheneedsoftheclientgiven throughthecommunications.6marks SubmityourreportandPythonfilesviaBlackboard,usingPDFforthereport(savedfrom WordorcreatedinLaTeX). Onlyonesubmissionperpairisnecessarybutmakesurebothnamesareclearlyshownon yourreport.Eachstudentwillreceiveseparatedatafromtheclientbutapairneedonly consideronedatasetinthereport. GradingCriteria Section A Marks 0 1 2 Data Missing some or all descriptions of data Correctly describes all data Stages Missing clear description of stages Correctly describes stages States Incorrect or missing description of states Correctly describes state for one communication Correctly describes states for all communications Actions Incorrect or missing description of actions Correctly describes actions for one communication Correctly describes actions for all communications Value function Incorrect or missing description of value functions Correctly describes value function for one communication Correctly describes value functions for all communications Python code There is no relationship between 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 incorrect answer Python code runs and gives correct 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 Correctly addresses one client question Correctly addresses all client questions Written response Poorly written response with frequent errors in grammar, spelling or technical language; and/or unnecessarily long Concisely addresses needs of client with few errors 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 DayMay 16, 2020MATH7232

Answer To: Microsoft Word - Assignment 3.docx MATH7232OperationsResearch&MathematicalPlanning2018...

Abr Writing answered on May 23 2020
148 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 order
In [5]:

# Creating an empty Dataframe
columns = ['Profit']
rows = (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.order
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 order
'''
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