Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Q5. (20p) Assume there are two dictionaries called Mid1 and Mid2. The dictionary Mid2 only includes a subset of Mid1. You want to calculate a

Q5. (20p) Assume there are two dictionaries called Mid1 and Mid2. The dictionary Mid2 only includes a subset of Mid1. You want to calculate a weighted average of these two dictionaries and write it to a new dictionary called Avg like the following: - If an entry exists in both of the dictionaries (Mid1 and Mid2), then take the average of them and set it as the value at the new dictionary Avg.. - Otherwise (i.e., if an entry is only at the first list), then directly write the value in the first dictionary as the new value. Note that there are no any other options, i.e. there are no entries that exist Mid2 but do not exist in Mid1. For example, if two dictionaries are given as follows,

Mid1 = {'S1': 55, 'S2': 50, 'S3': 70}

Mid2 = {'S1': 95, 'S3': 90, } then the resulting dictionary Avg will be Avg = {'S1': 75, 'S2': 50, 'S3': 80}

Write the required python code.

image text in transcribed

Q4.(20p) Consider the following optimization problem that is coded in CBC. from pulp import* Factory = ["A", "B"] Mall = ["M1", "M2", "M3", "M4"] Prod = {"A": 1000,"B": 2000} Sales = {"M1": 1500,"M2": 600,"M3": 700,"M4": 200} Cost = {"A": {"M1":2, "M2":4, "M3":5, "M4":2}, "B": {"M1":3, "M2":1, "M3":3, "M4":2}} prob = LpProblem("Final Exam", LpMinimize) X = LpVariable.dicts("x",(Factory, Mall), lowBound = 0, upBound = None, cat = const.LpInteger) prob += lpSum(Cost[f][s]*X[a][b] for f in Factory for s in Mall) for w in Factory: prob += lpSum(X[f][s] for s in Mall) = Sales[s] a. b. We are trying to model the sales distribution channel of a supply chain. There are two factories (A, B) and four Malls (M1,M2,M3,M4). On the left you can see the Python code of the optimization problem for CBC library. Please solve the following questions.

a. Write the mathematical model of the second for loop that is written in bold.

b. Assume factory B cannot serve second and third mall, i.e. there is no flow from factory B to M2 and M3. Write the mathematical equation for this constraint

image text in transcribed

Q5. (20p) Assume there are two dictionaries called Mid1 and Mid2. The dictionary Mid2 only includes a subset of Mid1. You want to calculate a weighted average of these two dictionaries and write it to a new dictionary called Avg like the following: - If an entry exists in both of the dictionaries (Mid1 and Mid2), then take the average of them and set it as the value at the new dictionary Avg.. - Otherwise (i.e., if an entry is only at the first list), then directly write the value in the first dictionary as the new value. Note that there are no any other options, i.e. there are no entries that exist Mid2 but do not exist in Mid1. For example, if two dictionaries are given as follows, Mid1 = \{'S1': 55, 'S2' : 50, 'S3': 70} Mid2 ={S1:95,S3:90,} then the resulting dictionary Avg will be Avg ={S1 ': 75, 'S2': 50, 'S3' : 80} Write the required python code. Q4. (20p) Consider the following optimization problem that is coded in CBC. We are trying to model the sales

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions