Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

from pulp import LpMinimize, LpProblem, LpStatus, lpSum, LpVariable, LpInteger, GLPK import numpy as np import random randomFloatList = [] Age = 20 #Maximum age f

from pulp import LpMinimize, LpProblem, LpStatus, lpSum, LpVariable, LpInteger, GLPK

import numpy as np

import random

randomFloatList = []

Age = 20 #Maximum age f bus (index = i)

Time_Period = 100 #Time periods considered (index = j)

age = list(range(Age))

time = list(range(Time_Period))

# Create the model

model = LpProblem(name="CampusTransportSystem", sense=LpMinimize)

# Initialize the decision variables

x = {(i,j): LpVariable(name=f"x{i,j}", lowBound=0, cat="Integer") for i in age for j in time}

y = {(i,j): LpVariable(name=f"y{i,j}", lowBound=0, cat="Integer") for i in age for j in time}

#3... define variables

#All should be random values #purchase cost of a bus (v)

v = list(np.random.randint(low = 737000, high = 958000, size = 100)) print(list(v)) #number of bus to be purchased p = list(np.random.randint(low = 1, high = 3, size = 100)) print(list(p))

#fuel price per gallon

g = list(np.random.randint(low = 2.64, high = 4.46, size = 100))

print(list(g))

#maintenance cost

m = list(np.random.randint(low = 7628, high = 8000, size = 100))

print(list(m))

#emission cost

e = list(np.random.randint(low = 3040, high = 10145, size = 100))

print(list(e))

#salvage value

s = list(np.random.randint(low = 1000, high = 5000, size = 100))

print(list(s))

#utilization cost

u = list(np.random.randint(low = 33000, high = 33045, size = 100))

print(list(u))

#fuel economy of a bus

for i in range(0, 19):

f = round(random.uniform(3.32, 3.65), 20)

randomFloatList.append(f)

print(randomFloatList)

#discount rate

#Each term in the model should have a diferent discount rate

for i in range(0, 5):

r = round(random.uniform(0.0955, 0.1), 5)

randomFloatList.append(r)

print(randomFloatList)

model += lpSum(v[j]*p[j]*(1+r)**(-j) for j in time) + \ lpSum(((g[j]*u[i])/f[i])*x[(i,j)]*(1+r)**(-j) for j in time for i in age) + \ lpSum((m[i]*u[i])*x[(i,j)]*(1+r)**(-j) for j in time for i in age) + \ lpSum(u[i]*e*x[(i,j)]*(1+r)**(-j) for i in age for j in time) - \ lpSum(s[i]*y[(i,j)]*(1+r)**(-j) for j in time for i in age)

type(expression)

# Add the constraints to the model

for j in time:

model += v[j]*p[j] <= b[j] # b=100000

for j in time:

model += [p[j] ] == [x[(0,j)]]

for j in time:

for i in age:

model += lpSum(u[i]*x[(i,j)]) >= d[j]

for i in age:

for j in time:

model += [x[(i-1,j-1)]] == [x[(i,j)] + y[(i,j)]]

for j in time:

model += [x[(M,j)]] == 0

for j in time:

model += [y[(0,j)] ] == 0

type(constraint)

# Solve the problem

status = model.solve()

print(f"status: {model.status}, {LpStatus[model.status]}")

print(f"objective: {model.objective.value()}")

for var in model.variables():

print(f"{var.name}: {var.value()}")

for name, constraint in model.constraints.items():

print(f"{name}: {constraint.value()}")

model.variables()

model.variables()[0] is x

model.variables()[1] is y

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

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

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

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

Question

3. Is it a topic that your audience will find worthwhile?

Answered: 1 week ago

Question

2. What do you believe is at the root of the problem?

Answered: 1 week ago