LotSizingDataModel.Solver.Cplex 2.0.1
IBM ILOG CPLEX adapter and installation discovery integration.
Loading...
Searching...
No Matches
CplexModelTranslationResult.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using ILOG.Concert;
4using ILOG.CPLEX;
5using NativeCplex = global::ILOG.CPLEX.Cplex;
6
8
9/// <summary>
10/// Stores the native CPLEX model objects created from one
11/// solver-independent mathematical model.
12/// </summary>
13public sealed class CplexModelTranslationResult
14{
15 private readonly IReadOnlyDictionary<int, INumVar>
16 _variablesById;
17
18 /// <summary>
19 /// Initializes a CPLEX translation result.
20 /// </summary>
21 /// <param name="cplex">
22 /// Native CPLEX model.
23 /// </param>
24 /// <param name="variablesById">
25 /// Mapping from generic mathematical-variable identifiers to
26 /// native Concert variables.
27 /// </param>
29 NativeCplex cplex,
30 IReadOnlyDictionary<int, INumVar> variablesById)
31 {
32 ArgumentNullException.ThrowIfNull(cplex);
33 ArgumentNullException.ThrowIfNull(variablesById);
34
35 Cplex = cplex;
36 _variablesById = variablesById;
37 }
38
39 /// <summary>
40 /// Gets the native CPLEX model.
41 /// </summary>
43 {
44 get;
45 }
46
47 /// <summary>
48 /// Gets the native variables indexed by generic identifier.
49 /// </summary>
50 public IReadOnlyDictionary<int, INumVar> VariablesById =>
51 _variablesById;
52
53 /// <summary>
54 /// Resolves a native variable by generic mathematical
55 /// identifier.
56 /// </summary>
57 /// <param name="variableId">
58 /// Generic mathematical-variable identifier.
59 /// </param>
60 /// <returns>
61 /// Native Concert variable.
62 /// </returns>
63 public INumVar GetVariable(
64 int variableId)
65 {
66 if (!_variablesById.TryGetValue(
67 variableId,
68 out INumVar? variable))
69 {
70 throw new InvalidOperationException(
71 $"No native CPLEX variable is registered for " +
72 $"mathematical variable identifier {variableId}.");
73 }
74
75 return variable;
76 }
77}
global::ILOG.CPLEX.Cplex NativeCplex
IReadOnlyDictionary< int, INumVar > VariablesById
Gets the native variables indexed by generic identifier.
CplexModelTranslationResult(NativeCplex cplex, IReadOnlyDictionary< int, INumVar > variablesById)
Initializes a CPLEX translation result.
INumVar GetVariable(int variableId)
Resolves a native variable by generic mathematical identifier.