The data

Shows how to specify the data source for your model.

To generate the CPLEX model, OPL needs to know where to take the data from. You must therefore specify a data source.

The data source can be:

  • either an OPL data file (as in the Tutorial) which allows access to data in files or databases, or

  • a custom-coded data source, as in the following examples. (The custom data source is described in Custom data sources.)

C++

C++: Specifying a data source

        MyParams params(env,argc,argv);
        IloOplDataSource dataSource(&params);
        opl.addDataSource(dataSource);
        opl.generate();

Java

Java: Specifying a data source

        IloOplDataSource dataSource=new MyParams(oplF,nbWarehouses,nbStores,fixed,disaggregate);
        opl.addDataSource(dataSource);
        opl.generate();

.NET (C#)

.NET: Specifying a data source

                OplDataSource dataSource = new MyParams(oplF, nbWarehouses, nbStores, fixedP, disaggregate);
                opl.AddDataSource(dataSource);
                opl.Generate();

Now, the OPL model is available from CPLEX. You can use the full IloCplex API to solve the model. You can reuse the same cplex instance for different OPL models. However, when you access for the first time a postprocessing model element that uses variable values in its definition, you may get an “unbound variable” exception if the cplex instance has been used later for another model and hence is not synchronized with the invoking model anymore.