【问题标题】:CPLEX constraintsCPLEX 约束
【发布时间】:2021-11-02 13:12:05
【问题描述】:

我需要优化具有最高总体影响的投资选择。 限制是总投资可以最大为 8.0 另一个限制是每个类别只能评估两次

我面临的问题是最大投资的约束不起作用。我也找不到如何实现类别约束。也欢迎提供相关表格的链接。

我的代码附在下面

非常感谢

--

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.0, 1.6, 2.5, 12.0, 10.3, 0.6, 1.2, 1.9, 4.0, 5.0, 0.2, 0.5]; // costs --> can be max 8.0 
string Category[Project] = [1,1,1,1,1,2,2,2,3,3,3,3] 
float Budget = 8.0;
// Declaration of Parameters 

//Expression of Decision 
dexpr float Reduction = sum(p in Project) Impact[p];

//Objective Function
maximize Reduction;

//Constraints
constraint ctCapResources[Project];
subject to {
forall (p in Project)
    ctCapResources[p]: sum(p in Project)
        Investment[p] <= Budget;
}

【问题讨论】:

    标签: cplex docplexcloud


    【解决方案1】:

    @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;
    }
    

    【讨论】:

      【解决方案2】:

      主要问题是您忘记添加决策变量。

      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.0, 1.6, 2.5, 12.0, 10.3, 0.6, 1.2, 1.9, 4.0, 5.0, 0.2, 0.5]; // costs --> can be max 8.0 
      int Category[Project] = [1,1,1,1,1,2,2,2,3,3,3,3];
      float Budget = 8.0;
      // Declaration of Parameters 
      
      // decision variable
      dvar boolean invest[Project];
      
      //Expression of Decision 
      dexpr float Reduction = sum(p in Project) Impact[p]*invest[p];
      
      //Objective Function
      maximize Reduction;
      
      //Constraints
      constraint ctCapResources[Project];
      subject to {
      forall (p in Project)
          ctCapResources[p]: sum(p in Project)
              Investment[p]*invest[p] <= Budget;
              
       //  each Category can only be assessed twice
       
       forall(c in 1..3) sum(p in Project:Category[p]==c) invest[p]<=2;
      }
      

      效果会更好

      对于你的第二个问题,你可以改变

      maximize Reduction;
      

      进入

      maximize staticLex(Reduction,-Cost);
      

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多