Hey all, im stuck on these problems:
3.1 Problem
Create parameters enjoy and billpaid that evaluate the monthly enjoyment rate and the
bills of each type paid in a given month.
3.2 Problem
How should the budget be balanced all through the year to maximize the enjoyment from
leisure?
This is code I have currently, i dont know where to go.
import sys
import numpy as np
from gamspy import (
Container,Set,Alias,Parameter,Variable,Equation,Model,Problem,Sense,Options,
Domain,Number,Sum,Product,Smax,Smin,Ord,Card,SpecialValues,
)
m = Container()
months = Set(m, 'months', records=['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'])
items = Set(m, 'items', records=['living', 'rent', 'mobile', 'gas_elec', 'car', 'tax'])
incomes = Set(m, 'incomes', records=['allowance', 'salary'])
month_index = Parameter(m, 'month_index', domain=[months], records=np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]))
enjoy = Parameter(m, 'enjoy', domain=[months])
enjoy[months] = month_index[months] * (13 - month_index[months])
billpaid = Parameter(m, 'billpaid', domain=[months, items], records=np.array([
[ 550, 630, 0, 0, 340, 0], # Jan
[ 550, 630, 135, 0, 340, 0], # Feb
[ 550, 630, 0, 0, 340, 0], # Mar
[ 550, 630, 135, 0, 340, 100], # Apr
[ 550, 630, 0, 0, 340, 0], # May
[ 550, 630, 135, 850, 340, 0], # Jun
[ 550, 630, 0, 0, 340, 0], # Jul
[ 550, 630, 135, 0, 340, 100], # Aug
[ 550, 630, 0, 0, 340, 0], # Sep
[ 550, 630, 135, 0, 340, 0], # Oct
[ 550, 630, 0, 0, 340, 0], # Nov
[ 550, 630, 135, 850, 340, 100], # Dec
]))
income = Parameter(m, 'income', domain=[incomes], records=np.array([150, 1900]))
leisure = Variable(m, 'leisure', domain=[months])
savings = Variable(m, 'savings', domain=[months])
income_total = income['allowance'] + income['salary'] # Total monthly income
leisure_lower = Equation(m, 'leisure_lower', domain=[months])
leisure_lower[months] = leisure[months] >= 165
# Define the objective function: Maximize enjoyment
max_leisure = Sum(months, enjoy[months] * leisure[months])
budget = Model(m,
name="budget",
equations=m.getEquations(),
problem="lp",
sense="max",
objective=max_leisure)
budget.solve(options=Options(equation_listing_limit=100))
print(budget.objective_value)