0

我想用 CPLEX-C# 解决 MILP 问题。我的问题很大,为了提高 CPU 时间,我想使用初始解决方案。我想将此解决方案添加到 cplex 中,并开始使用给定的初始解决方案来解决问题。我使用了以下代码:

     try
        {
            startvar = new INumVar[numberOfAllNode * numberOfAllNode];
            startval = new double[numberOfAllNode * numberOfAllNode];

            for (int i = 0, idx = 0; i < numberOfAllNode; i++)
                for (int j = 0; j < numberOfAllNode; j++)
                {
                    startvar[idx] = X[i][j];
                    startval[idx] = start[i][j];
                    idx++;
                }

            startvar = null;
            startval = null;

            cplex.AddMIPStart(startvar, startval,Cplex.MIPStartEffort.SolveMIP);

        }
    catch (ILOG.Concert.Exception)
        {
            throw;
        }

在这段代码中,我有多维数组决策变量X[i][j](二元决策变量),并且值等于start[i][j]. 的值start[i][j]存储double [] array为参数。当我运行代码时,出现以下错误:

Warning:  No solution found from 1 MIP starts.

Root node processing (before b&c):
  Real time             =    5.07 sec. (2238.50 ticks)
Parallel b&c, 4 threads:
  Real time             =    0.00 sec. (0.00 ticks)
  Sync time (average)   =    0.00 sec.
  Wait time (average)   =    0.00 sec.
                          ------------
Total (root+branch&cut) =    5.07 sec. (2238.50 ticks)
Couldn't Solve The Problem! 

我有两个问题:1)我必须把这段代码放在模型的哪个部分?(我的意思是在所有约束之后添加目标值并调用 addMin 或 addMax 或在它们之前?)

2)当我表扬startvar = null; startval = null;我有以下错误:

An unhandled exception of type 'ILOG.CPLEX.Cplex.UnknownObjectException' occurred in CPLEX.exe

Additional information: CPLEX Error: object is unknown to IloCplex 

如果您能帮助解决这个问题,我将不胜感激。

4

1 回答 1

0

非常类似于在 CPLEX C++但在 C#中使用 addMIPStart() 时出错。

我通常会在模型构建结束时调用 AddMIPStart(),就在 solve() 之前。那是(对我来说)打电话的“自然”地方。

如果您的模型中有任何约束或目标中未提及的变量,那么当 CPLEX 从 Concert 表达式等中提取内部模型时,它不会将它们包含在其内部模型中。然后,如果您尝试为这些变量设置值,CPLEX 将无法识别它们。我会检查你的 mip start 中的所有变量是否确实包含在你的约束或目标中的某个地方。

于 2017-05-16T08:42:00.500 回答