Imports model from a file.

Namespace: ILOG.CP
Assembly: oplall (in oplall.dll)

Syntax

C#
public virtual void ImportModel(
	string filename
)

Parameters

filename
Type: System..::..String

Remarks

This method reads a model from a file specified by the filename parameter. The file must have extension .cpo and follow the syntax described in the CP Optimizer File Format Reference Manual.

Before reading the file, the function first discards any model that was used before.

The file may also specify values of CP Optimizer parameters (in section parameters). Parameters that are not specified in the file are reset to their default values. Note that parameters that affect the import process itself (such as [!:IntParam#UseFileLocations]) could be set before importModel and the setting is respected during the import however those parameters are also reset to default values (unless specified otherwise in the file).

If an error happens while reading the file then the error messages are written into the stream defined by SetError(TextWriter) and the function throws an instance of IloException.

This method cannot be called during the search.

After reading the model, it is possible to access some model objects (especially variables) using the functions GetAllIIntVars()()()(), GetAllIIntervalVars()()()(), GetAllIIntervalSequenceVars()()()(), GetAllIStateFunctions()()()() and GetAllConstrainedICumulFunctionExprs()()()(). It is also possible to access modeling objects by name using functions GetIIntVar(String), GetIIntervalVar(String), GetIIntervalSequenceVar(String), GetIStateFunction(String) and GetICumulFunctionExpr(String).

Once the model is loaded it is possible to modify domains of the model variables but otherwise the model cannot be changed.

For example, lets assume that there is a file colors.cpo with the following content (model of a map coloring problem):

                // Decision variables:
                Belgium = intVar(1..4);
                Denmark = intVar(1..4);
                France = intVar(1..4);
                Germany = intVar(1..4);
                Luxembourg = intVar(1..4);
                Netherlands = intVar(1..4);
            
                // Constraints:
                Belgium != France;
                Belgium != Germany;
                Belgium != Netherlands;
                Belgium != Luxembourg;
                Denmark != Germany;
                France != Germany;
                France != Luxembourg;
                Germany != Luxembourg;
                Germany != Netherlands;
            
                parameters {
                  SearchType = DepthFirst;
                }
             

The following code reads the model from the file, modifies domain of variable France, solves it and prints the solution.

Examples

CP cp = new CP(); cp.ImportModel("color.cpo"); IIntVar varFrance = cp.GetIIntVar("France"); varFrance.Min = 4; cp.Solve(); Console.WriteLine("Belgium: " + cp.GetValue("Belgium")); Console.WriteLine("Denmark: " + cp.GetValue("Denmark")); Console.WriteLine("France: " + cp.GetValue("France")); Console.WriteLine("Germany: " + cp.GetValue("Germany")); Console.WriteLine("Luxembourg: " + cp.GetValue("Luxembourg")); Console.WriteLine("Netherlands: " + cp.GetValue("Netherlands"));

See Also