是AMPL的新手。
在混合问题中,我已经通过最大化利润解决了模型。
此外,我正在尝试计算给定数量产品的单价,以便以一定百分比增加利润。
是否可以直接在运行中执行此操作。 ?
通过应用“ let”,我可以更改可用产品的数量,但是我正在努力弄清楚如何将产品的价格设置为变量?我该怎么办?
谢谢。
[您要在这里做几件事。
一种解决方案是修改问题,要求利润比问题的先前版本至少好X%。可以按照以下步骤进行:
profit_0
等于旧问题的收益。1.05*profit_0
或任何要求。另一种方法是将某些价格视为固定价格,而另一些视为变量。可能最简单的方法是将它们全部定义为变量,然后将其中一些约束为固定值。
用AMPL编码这些代码不是很困难,我将在下面给出一个语法示例。不幸的是,您将(可变价格)乘以(购买的可变数量)来找到成本的事实意味着您最终遇到了二次约束,许多求解器都会拒绝。
在此示例中,我使用了Gecode,它对于此类问题并不理想(特别是,它要求所有变量均为整数),但至少允许二次约束:
reset;
option solver gecode;
# all the "integer" constraints in this example are there because
# gecode won't accept non-integer variables; ideally they wouldn't
# be there.
# To keep the demo simple, we assume that we are simply buying
# a single ingredient from suppliers and reselling it, without
# blending considerations.
param ingredients_budget;
# the maximum we can spend on buying ingredients
set suppliers;
param max_supply{suppliers};
# maximum amount each supplier has available
var prices{suppliers} integer >= 0;
# the amount charged by each supplier - in fact we want to treat
# some of those as var and some as constant, which we'll do by
# fixing some of the values.
param fixed_prices{suppliers} default -1;
# A positive value will be interpreted as "fix price at this value";
# negative will be interpreted as variable price.
s.t. fix_prices{s in suppliers: fixed_prices[s] > 0}:
prices[s] = fixed_prices[s];
param selling_price;
var quantity_bought{s in suppliers} >= 0, <= max_supply[s] integer;
var quantity_sold integer;
s.t. max_sales: quantity_sold = sum{s in suppliers} quantity_bought[s];
var input_costs integer;
s.t. defineinputcosts: input_costs = sum{s in suppliers} quantity_bought[s]*prices[s];
s.t. enforcebudget: input_costs <= ingredients_budget;
var profit integer;
s.t. defineprofit: profit = quantity_sold*selling_price - input_costs;
maximize OF1: profit;
data;
param ingredients_budget := 1000;
set suppliers :=
S1
S2
;
param max_supply :=
S1 100
S2 0
;
param fixed_prices :=
S1 120
;
param selling_price := 150;
model;
print("Running first case with nothing available from S2");
solve;
display profit;
display quantity_bought;
display quantity_sold;
param profit_0;
let profit_0 := profit;
param increase_factor = 0.05;
let max_supply["S2"] := 100;
s.t. improveprofit: profit >= (1+increase_factor)*profit_0;
maximize OF2: prices["S2"];
objective OF2;
print("Now running to increase profit.");
solve;
display profit;
display quantity_bought;
display quantity_sold;
display prices["S2"];
[另一种选择是使用AMPL's looping commands重复运行相同的问题,但是每次更改相关的价格值,以查看哪个价格值可提供可接受的利润。如果这样做,则无需将price声明为var,只需将其设为param并使用“ let”在场景之间进行更改即可。这将避免二次约束,并允许您使用CPLEX和Gurobi等MIP求解器。
您也可以在Operations Research SE上询问,您在哪里可以获得比我能给您的更好的答案。