Cplex 12.7 GetValue() problem

27 views
Skip to first unread message

Ali Pala

unread,
Jan 10, 2022, 6:20:42 AM1/10/22
to OPTANO Modeling
Hi,

When using Cplex 12.7, we obtain the optimal solution on our Solution object, but get the below error message. Same model works with Gurobi with no issues. Therefore, it looks like the problem is related to Cplex 12.7.

at ILOG.CPLEX.Cplex.GetValues(INumVar[] var, Int32 start, Int32 num)

at ILOG.CPLEX.Cplex.GetValues(INumVar[] var)

at OPTANO.Modeling.Optimization.Solver.Cplex127.CplexSolver.SolveAdapterSpecific(Int32 prioLevel, IDictionary`2 variableValues)

at OPTANO.Modeling.Optimization.SolverBase.CallSolveOnAdapter(Int32 prioLevel, Dictionary`2 variableValues, Boolean isResolve)

at OPTANO.Modeling.Optimization.SolverBase.BuildConfigureAndSolveOnAdapter(Int32 prioLevel, Dictionary`2 variableValues, Boolean isResolve, TimeSpan gloablElapsedTime)

at OPTANO.Modeling.Optimization.SolverBase.BuildConfigureAndSolveOnAdapter(Int32 prioLevel, Dictionary`2 variableValues, Boolean isResolve)

at OPTANO.Modeling.Optimization.SolverBase.SolveSingleStageModel(Dictionary`2 startSolution, Boolean isResolve, List`1 objectiveStages)

at OPTANO.Modeling.Optimization.SolverBase.SolveNonNative(Dictionary`2 variableValues, Boolean isResolve)

at OPTANO.Modeling.Optimization.SolverBase.Solve(Model model, Dictionary`2 variableValues)

 Any suggestions regarding that question?

OPTANO Team

unread,
Jan 10, 2022, 7:12:45 AM1/10/22
to OPTANO Modeling
Hi,

please find attached a mini demo using cplex 12.7 and retrieving the variable values.
Does this example run on your system?

Please copy the 3 cplex 12.7 files in the same folder.

Best
jp
cplextrial.7z

OPTANO Team

unread,
Jan 10, 2022, 7:14:47 AM1/10/22
to OPTANO Modeling
Program.cs
// See https://aka.ms/new-console-template for more information

using OPTANO.Modeling.Common;
using OPTANO.Modeling.Optimization;
using OPTANO.Modeling.Optimization.Enums;

Console.WriteLine("Starting CPLEX Test");
var model = new Model();

var x = new Variable("x", 0, double.PositiveInfinity, VariableType.Integer);
var y = new Variable("y", 0, double.PositiveInfinity, VariableType.Integer);


model.AddObjective(new Objective(2 * x + y + 10, "goal", ObjectiveSense.Maximize), "goal");

model.AddConstraint(x + y <= 100);

var solver = new OPTANO.Modeling.Optimization.Solver.Cplex127.CplexSolver();
var solution = solver.Solve(model);
Console.WriteLine($"This is {solver}");
Console.WriteLine($"Finished with status {solution.Status}");

//solve retrieves values per default configuration automatically
Console.WriteLine($"Variable x is {x.Value}");
Console.WriteLine($"Variable y is {y.Value}");



trial.csproj
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <PlatformTarget>x64</PlatformTarget>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="optano.modeling" Version="3.10.0.538" />
  </ItemGroup>

  <ItemGroup>
    <Reference Include="ILOG.Concert">
      <HintPath>ILOG.Concert.dll</HintPath>
    </Reference>
    <Reference Include="ILOG.CPLEX">
      <HintPath>ILOG.CPLEX.dll</HintPath>
    </Reference>
  </ItemGroup>

  <ItemGroup>
    <None Update="cplex1270.dll">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>

</Project>

Ali Pala

unread,
Jan 11, 2022, 4:37:29 AM1/11/22
to OPTANO Modeling
It worked out, thanks.

OPTANO Team

unread,
Jan 11, 2022, 5:29:21 AM1/11/22
to OPTANO Modeling

Perfect. Happy to help!
jp
Reply all
Reply to author
Forward
0 new messages