在cplex/opl中初始化一个集合

initializing a set in cplex/opl

本文关键字:一个 集合 初始化 cplex opl      更新时间:2023-09-26

我目前正致力于在cplex中实现的多容量批量问题的基础上,在买方和供应商之间建立谈判。在一个小场景中,买方生产项目1-4,而供应商负责供应项目5-7。

我想做的是创建三个集合:

{int} buyeroperations
{int} supplieroperations
{int} operations = buyerops union supplierops

我现在的问题是,由于我对cplex/opl还很陌生,如何用相应的项初始化集合,以便在我的模型中使用它们。我想我可以通过以下方式在内部初始化它们:

{int} buyeroperations = asSet(1..4) 
{int} supplieroperations = asSet(5..7) 
{int} operations = buyeroperations union supplieroperations

我说得对吗?但是,我可以通过脚本和for循环以不同的方式初始化集合吗?

如上所述,最终我想要三套,前四个项目被分配给买方操作,项目5-7被分配给供应商操作,然后是关于所有项目的一套操作。

感谢您提前提供的帮助。

我会把模型和数据文件分开,这样做会更容易。在模型文件中,我将有:

{int} buyeroperations = ...;
{int} supplieroperations = ...;
{int} operations = buyeroperations union supplieroperations;

在数据文件中,我会有:

buyeroperations = [1,2,3,4] // same as [1..4]
supplieroperations = [5,6,7] // same as [5..7]

如果有大量数据,初始化集合的最佳方法是使用数据库。你展示的也应该有效。