如何处理依赖于另一个变量的变量,例如Gurobi python界面中的需求和价格

时间:2019-06-01 09:22:15

标签: python gurobi

我正在编写一个优化模型,以使航空公司的利润最大化。

  1. 利润=收入-费用+政府补贴
  2. 我正在将收入计算为需求*机票价格

价格是航空公司可以选择的决策变量,这会影响需求,我也将其视为决策变量。

无论是函数还是约束,我如何最好地表达这种需求价格关系。 另外,我的目标函数在价格上看起来是二次方,您知道显式声明此目标函数的方法吗?

我正在使用gurobypy-Gurobi python接口。以下是到目前为止我所做的最少示例-由于问题不需要它,因此我没有包括governemnt_subsidies。

#--------------------------------
#input data
#--------------------------------
# A list of regions. set R
regions = ["Region_1", "Region_2"]
# A list of airports involved in the auction. set I
airports = ["A", "B"]
# A list of routes R
routes = ["A-B-ARN", "A-ARN", "B-ARN"]
Cost_bh = {
    "A-B-ARN" : 726,
     "A-ARN" : 1116,
     "B-ARN" : 1473
 }

#parameter variables
incidence_matrix_G = dict({
    ("A-B-ARN","A") : 1,
    ("A-B-ARN", "B") : 1,
    ("A-ARN","A" ) : 1,
    ("A-ARN", "B") : 0,
    ("B-ARN","A" ) : 0,
    ("B-ARN", "B") : 1
 })

route_bh = {
     "A-B-ARN" : 2.44,
     "A-ARN" : 1.41,
     "B-ARN" : 1.71
 }

route_maxflights = {
     "A-B-ARN" : 18,
     "A-ARN" : 12,
     "B-ARN" : 12
 }
route_maxprice = {
     "A" : 1300,
     "B" : 1000
 }

catchment = {
     "A-B-ARN" :  283475 ,
     "A-ARN" :  283475 ,
     "B-ARN" :  556465 
 }
#--------------------------------
# Create a new model
#--------------------------------
model = Model("Airline Profit")

#variables
price = {} # the prices an airline is charging per route, and airport
Demand= {} # the price responsive demand an airline gets per route and airport

#Define variables

# define price per route per airport
for route in routes:
    for airport in airports:
        price[route, airport] = model.addVar(vtype=GRB.CONTINUOUS,
                                              name="price_{}_{}".format(route, airport))
# define demand per route per airport, based on the price
for route in routes:
    for airport in airports:
        Demand[route, airport] = model.addVar(vtype=GRB.CONTINUOUS,
                                             name="Demand_{}_{}".format(route, airport))
m.update()

#AK add constraints 
for route in routes:
    for airport in airports:
        Demand[route, airport] =  0.005 + (1.5434*np.log(catchment[route]))-(0.6774*np.log(route_bh[route]))-(1.8963*price[route, airport])

model.addConstrs((price[route, airport]  <= route_maxprice[airport] for route in routes for airport in airports), "price_cap")

# Set objective function components
#AK the revenue for the airline
obj_revenue = quicksum(incidence_matrix_G[route, airport]*Demand[route, airport]*price[route, airport]*route_maxflights[route] for route in routes for airport in airports)

#The total operation cost; cost_bh is aircraft and route
# cost_bh is precomputes for a given route based on the used aircraft
obj_cost_operation = quicksum(Cost_bh[route]*route_bh[route]*route_maxflights[route] for route in routes)

Obj_airline = obj_revenue - 2*obj_cost_operation
model.setObjective(Obj_airline, GRB.MAXIMIZE)

我目前正在得到一些结果,但是我知道它们是不正确的,因为当我做print(Demand.values())时,我会得到:

dict_values([<gurobi.LinExpr: 18.777961108358838 + -1.8963 price_A-B-ARN_A>, <gurobi.LinExpr: 18.777961108358838 + -1.8963 price_A-B-ARN_B>, <gurobi.LinExpr: 19.14945291443028 + -1.8963 price_A-ARN_A>, <gurobi.LinExpr: 19.14945291443028 + -1.8963 price_A-ARN_B>, <gurobi.LinExpr: 20.05977292744191 + -1.8963 price_B-ARN_A>, <gurobi.LinExpr: 20.05977292744191 + -1.8963 price_B-ARN_B>])

我的看法是,如果这行得通,我将获取实际值而不是线性表达式。

谢谢您的帮助。

0 个答案:

没有答案