@alexfleischer - 非常感谢亚历克斯。非常感激。我有一个后续问题。我已经包含了两种制造方法(即内部和外部)的索引,并希望添加以下限制: • 以下三个项目中最多一个可以在内部完成:项目 1、项目 4、项目 5。此外,我注意到,虽然实现了最佳结果(最高影响),但它没有考虑成本(有两个答案产生相同的影响但成本不同),而我想将其作为次要(不太重要)目标(应该是可能的)使用 CPLEX 12.9?)
int NumberofProduction = 2;
range Production = 1..NumberofProduction; // Internal vs External production
int NumberofProjects = 12;
range Project = 1..NumberofProjects; // 12 different projects
//Declaration of Parameters
float Impact[Project] = [0.1, 0.03, 0.07, 0.13, 0.01, 0.04, 0.07, 0.08, 0.15, 0.12, 0.02, 0.04]; // Impact to maximize
//float Investment[Project] = [2.3, 1.7, 2.9, 2.3, 0.4, 0.7, 1.4, 2.2, 4.5, 5.5, 0.3, 0.6]; // costs --> can be max 8.0
// float Setupcosts[Project] = [0.3, 0.1, 0.4, 0.3, 0.1, 0.1, 0.2, 0.3, 0.5, 0.5, 0.1, 0.1];
// float ExInvestment[Project] = [2.5, 1.7, 2.0, 2.5, 0.4, 0.7, 1.8, 2.2, 4.5, 1.0, 0.4, 0.5];
float InExInvestment[Production][Project] = [[2.3, 1.7, 2.9, 2.3, 0.4, 0.7, 1.4, 2.2, 4.5, 5.5, 0.3, 0.6],[2.5, 1.7, 2.0, 2.5, 0.4, 0.7, 1.8, 2.2, 4.5, 1.0, 0.4, 0.5]];
int Category[Project] = [1,1,1,1,1,2,2,2,3,3,3,3];
float Budget = 8.0;
// decision variable
dvar boolean invest[Production][Project];
//Expression of Decision
dexpr float Reduction = sum(q in Production, p in Project) Impact[p]*invest[q][p];
// dexpr float Costs = sum(q in Production, p in Project) -1*InExInvestment[q][p]; // Second decision to mimimize costs if two options for Reduction with same outcome
//Constraints
constraint ctCapResources[Project];
constraint ctProject[Project];
//Objective Function
maximize Reduction;
subject to {
// each Category can only be assessed twice
forall (p in Project)
ctProject[p]: sum(q in Production)invest[q][p] <=1;
forall(c in 1..3) sum(p in Project:Category[p]==c, q in Production) invest[q][p]<=2;
forall (p in Project)
ctCapResources[p]: sum(q in Production, p in Project)
InExInvestment[q][p]*invest[q][p] <= Budget;
}