Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I would like to know if my code is correct for the following question and pls edit the part where its giving an error Question
I would like to know if my code is correct for the following question and pls edit the part where its giving an error
Question : Discrete Optimization: Consider each of the three levels for each of the five attributes
and enumerate all the possibilities in lexical order with Price as the leftmost attribute
changing slowest and taking levels sequentially $ $ $ then Time Insulated as
the leftsecondmost attribute changing secondslowest and taking values sequentially
hrs hr hrs and so on You will have product candidates. The lexical order
produces indices as shown in mugsproductslexicalorder.csv Please make sure
you list your products in that exact same order. The lexical order of products is
obtained by looping as shown in mugsproductslexicalorderloop.R which has
close similarity in python. Again, using the compensatory rule, compute and report
the following four columns of numbers for each candidate: the share, the cost, the
margin and the expected profit per person all under the current competition
incumbents The table that you submit needs to have all rows. Hint to check your
answer: product candidate has a negative expected profit per customer of between
and and product candidate has an expected profit per customer of
between and
Code :
import numpy as np
# Define the incumbents' attributes
incumbentattributes
$ hrs oz 'Clean Easy', 'Leak resistant', 'Brand A
$ hrs oz 'Clean Fair', 'Spill resistant', 'Brand B
$ hrs oz 'Clean Easy', 'Leak resistant', 'Brand C
# Define the scaling constant
c
# Define the attribute levels
attributelevels
$$$
hrs hrs hrs
oz oz oz
Difficult min 'Fair min 'Easy min
Slosh resistant', 'Spill resistant', 'Leak resistant'
Brand A 'Brand B 'Brand C
# Initialize the partworth utility matrix
partworthutilities npzeros
# Function to compute utility
def computeutilitycandidate incumbent:
diff sumc candidatea incumbenta for a in range sumc candidatea incumbenta for a in range
return npexpdiff
# Generate candidate attributes and compute utilities
for i price in enumerateattributelevels:
for j time in enumerateattributelevels:
for k capacity in enumerateattributelevels:
for l cleanability in enumerateattributelevels:
for m containment in enumerateattributelevels:
for n brand in enumerateattributelevels:
# Generate candidate attributes
candidateattributes price time, capacity, cleanability, containment, brand
# Compute utilities for each attribute
utilities computeutilitycandidateattributes, incumbent for incumbent in incumbentattributes
# Average utility for the candidate product
avgutility npmeanutilities
# Update partworth utilities matrix
for a in range:
partworthutilitiesa n avgutility
# Normalize the partworth utilities by the number of combinations
numcombinations lenattributelevels lenattributelevels lenattributelevels lenattributelevels lenattributelevels
partworthutilities numcombinations
printpartworthutilities
cleanabilitymapping
'Difficult': 'Difficult min
'Fair': 'Fair min
'Easy': 'Easy min
# Import the dataset
df pdreadcsvmugsproductslexicalorder.csv
# Define the levels for each attribute
pricelevels $$$
timeinsulatedlevels hrs hr hrs
# Modified calculatemetrics function using the previously defined utility and cost calculation logic
def calculatemetricsprice timeinsulated, capacity, cleanability, containment, brand:
candidate price timeinsulated, capacity, cleanability, containment, brand
utilities computeutilitycandidate incumbent for incumbent in incumbentattributes
share expnpmeanutilities sumexpu for u in utilities
cost coststimeinsulated'timeinsulated costscapacitycapacity costscleanabilitycleanability costscontainmentcontainment
margin floatprice: cost
expectedprofitperperson share margin
return share, cost, margin, expectedprofitperperson
# Loop through the dataset
for index, row in dfiterrows:
# Access data for each attribute
price row $strip
timeinsulated row hrsstrip
capacity row ozstrip
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started