【问题标题】:Creating a new set from components of an existing set in OPL/CPLEX从 OPL/CPLEX 中现有集的组件创建新集
【发布时间】:2018-06-30 01:27:27
【问题描述】:

我有一组已读入我的 OPL 项目,如下所示:

S = {<"A","">, <"B","">, <"AB","A">, <"AB","B">, <"C","">, <"ABC","A">,<"ABC","B">, <"ABC","C">, <"ABC","AB">},

其中每个元素 是一个包含两个字符串元素的元组。该集合表示感兴趣的项目之间的父子关系。

我需要从这个集合中创建一个新集合:

S' = {<"A",{""}>, <"B",{""}>, <"C",{""}>, <"AB",{"A","B"}>, <"ABC",{"A","B","C","AB"}>},

其中每个元素 是一个元组,每个元组的第一个元素是一个字符串,每个元组的第二个元素是一组字符串。我创建这个集合的尝试是:

tuple child{
    string Item;
    string Child; 
 }

 {child} Children = ...; //Reads in the set S

 tuple dependents{
    string Item;
    {string} ItemChildren; 
 } 

 {dependents} dependentsSet = {<x.Item, y.Child> | x in Children, (y in Children : <x,y> in Children)};

使用上面代码中的变量名,创建 S' 的目的是因为稍后在我的程序中我需要创建一个约束集合,每个项目一个,并且在每个约束中我需要对 ItemChildren 进行索引。我是 OPL 的相对新手,所以我知道我在dependentsSet 变量的初始化中错误地使用了语法,但我不知道如何正确编写此语句以创建我正在寻找的集合。

谁能帮我理解创建我所追求的集合所需的语句?

【问题讨论】:

    标签: optimization mathematical-optimization linear-programming cplex opl


    【解决方案1】:
    tuple child{
        string Item;
        string Child; 
     }
    
     {child} Children 
      = {<"A","">, <"B","">, <"AB","A">, <"AB","B">, <"C","">, <"ABC","A">,
      <"ABC","B">, <"ABC","C">, <"ABC","AB">};
    
    {string} setOfParents={i.Item | i in Children};
    {string} setOfChildren={i.Child | i in Children};
    
     tuple dependents{
        string Item;
        {string} ItemChildren; 
     } 
    
     {string} kids[p in setOfParents]={k | k in setOfChildren : <p,k> in Children};
    
     {dependents} dependentsSet = {<x, kids[x]> | x in setOfParents};
     execute
     {
    
     writeln(dependentsSet);
    } 
    

    给予

     {<"A" {""}> <"B" {""}> <"AB" {"A" "B"}> <"C" {""}>
     <"ABC" {"A" "B" "C" "AB"}>}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-11
      • 1970-01-01
      • 1970-01-01
      • 2013-06-25
      相关资源
      最近更新 更多