Home
IBM ILOG OPL Interface User`s Manual
Contents
1. Now the OPL model is available from CPLEX You can use the full 110Cp1ex 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 M ILOG OPL INTERFACE USER S MANUAL 45 Services on solutions Additional services are available through the IloOp1Model instance as soon as a solution is available The values for decision variables within the solution are accessible by their names See Accessing elements 46 IBM ILOG OPL INTERFACE USER S MANUAL Custom data sources You can provide OPL models with custom data sources by extending the class Ilo0plDataSourceBasel All you need to do is implement the read method which will be called by the OPL interpreter as necessary A custom data source uses the interface IloOplDataHandler to transfer data to the model and the method getDataHandler to access the associated data handler and send events The handler API is event driven similar to SAX interfaces for XML Two examples of how these handlers could be used to initialize custom data sources are given below Initialization of a multi dimensional array custom data source handler StartElement cost handler StartInde
2. Java IloOplModelSource modelSource oplF createOplModelSource DATADIR mulprod mod NET Visual Basic Dim modelSource As OplModelSource oplF CreateOplModelSource DATADIR mulprod mod To identify the model definition Use same model definition to instantiate one or more models C IloOplSettings settings env handler IloOplModelDefinition def modelSource settings Java IloOplModelDefinition def oplF createOplModelDefinition modelSource settings NET Visual Basic Dim def As OplModelDefinition oplF CreateOplModelDefinition modelSource settings To create the engine instance 4 Create the instance of the algorithm to use for this model C IloCplex cplex env Note If the model is to be solved by CP Optimizer engine you would instantiate an I1oCP object using IloCP cp env Java IloCplex cplex oplF createCplex Note If the model is to be solved by CP Optimizer engine you would instantiate an I1oCP object using 30 IBM ILOG OPL INTERFACE USER S MANUAL B M IloCP cp oplF createCP NET Visual Basic Dim cplex As Cplex oplF CreateCplex Note If the model is to be solved by CP Optimizer engine you would instantiate an I1oCP object using Dim cp As CP oplF CreateCP To create the OPL model You can now create the OPL model The constructor takes a model definition instance and an instance of IloCplex C IloOplModel opl def cplex
3. oe E ink pe ctra as no es t arroyos lt 2 23 53 1 IBM ILOG OPL INTERFACE USER S MANUAL 55 Settings 56 IBM There are various options available through the class 1100p1Settings to customize the behavior of OPL There is an accessor to retrieve the settings of an OPL model object You can set for example whether decision variable names are generated or not or whether source locations are associated with Concert objects or not See the C Interfaces Reference Manual for a complete list ILOG OPL INTERFACE USER S MANUAL Postprocessing solutions As modeling and solving are two separated phases the OPL model does not know when a solution is available Therefore it does not know when to postprocess that solution You must therefore initiate the call to postprocessing Note To avoid unexpected behavior you are recommended to call the postprocess method even if your model does not contain a postprocessing block C C Calling the postprocessing phase Java Java Calling the postprocessing phase ist Ep ES Ole ime System out println OBJECTIVE opl getCplex getObjValue opl postProcess opl printSolution System out status 0 FP else 4 System out println No solution status 1 oplF end NET CH Visualizing intermediate data if cplex Solve Console Out WriteLine OBJECTIVE opl Cplex ObjValue opl PostProcess 7 opl PrintSol
4. opl printSolution cout Java opl printSolution System out NET Visual Basic snippet_N3247F Accessing the solution through Concert You can use the typical Concert API to access results C cout lt lt endl lt lt MOBTECIIVES lt lt fixed lt lt Se tprecis ton 2 opis getCplex getObjValue lt lt endl Java System out println OBJECTIVE opl getCplex getObjValue NET Visual Basic snippet N324EE In the same way you can ask the 11oCplex instance for the values of the variables from the OPL model See Using OPL model instances for details IBM ILOG OPL INTERFACE USER S MANUAL 35 Using run configuration and projects 36 B M Sometimes itis not necessary to create intermediate objects for the model definition or the data sources as explained in Creating an OPL model This is the case for example when you do not plan to use the data source object for various different OPL models You can then use the classes I1o0plProject and I1o0p1RunConfiguration to create the 1100p1Model instance directly This section demonstrates this feature using the op1run example which exists in all four languages at the following locations lt OPL_dir gt examples opl_interfaces cpp src oplrunsample cpp lt OPL _dir gt examples opl_interfaces java oplrunsample src oplrunsample OpIRunSample java lt OPL dir vxamplesopl interfacesdotnetx86 net2005 8 0 VisualBasicOpIRunSample OplRunSample v
5. M C IloNumMap supplyMap supply asNumMap double supplyl supplyMap get 1 Java IloNumMap supplyMap supply asNumMap double supplyl supplyMap get 1 NET INumMap supplyMap supply AsNumMap double supplyl supplyMap Get 1 LOG OPL INTERFACE 7 7 USE R S MANUAL 53 Iterating through OPL elements 54 B M The OPL Interface libraries enable your applications to iterate through OPL elements such as arrays maps and sets This feature is illustrated by the iterators example which contains two samples The iterators example is available in C Java and NET Visual Basic and C at the following locations lt OPL_dir gt examples opl_interfaces cpp src iterators cpp lt OPL_dir gt examples opl_ interfaces java iterators src iterators Iterators java lt OPL_dir gt examples dotnet x86_ net2005_8 0 VisualBasic Iterators Iterators vb lt OPL_dir gt examples dotnet x86_ net2005 8 0 CSharp Iterators Iterators cs where lt OPL_dir gt is your installation directory Sample The purpose of Sample1 is to check the result of filtering by iterating on the generated data element The data element is an array of strings that is indexed by a set of strings It is filled as the result of an iteration on a set of tuples by filtering out the duplicates It is based on the transp2 mod model The simplified model is sinet c MEG clie SM E oxi e Route NS T og Selno OP eriak GUT
6. a um wy murum mu ES mmm umm umm z w um mum A a uw X NENNEN A m Y E IBM ILOG OPL V6 3 IBM ILOG OPL Interface User s Manual O Copyright International Business Machines Corporation 1987 2009 US Government Users Restricted Rights Use duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp Copyright COPYRIGHT NOTICE O Copyright International Business Machines Corporation 1987 2009 US Government Users Restricted Rights Use duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp Trademarks IBM the IBM logo ibm com WebSphere ILOG the ILOG design and CPLEX are trademarks or registered trademarks of International Business Machines Corp registered in many jurisdictions worldwide Other product and service names might be trademarks of IBM or other companies A current list of IBM trademarks is available on the Web at Copyright and trademark information at http Awww ibm com legal copytrade shtml Adobe the Adobe logo PostScript and the PostScript logo are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States and or other countries Linux is a registered trademark of Linus Torvalds in the United States other countries or both Microsoft Windows Windows NT and the Windows logo are trademarks of Microsoft Corporation in the United States other countries or both Java and all Java base
7. Java IloOplModel opl oplF createOplModel def cplex NET Visual Basic Dim opl As OplModel oplF CreateOplModel def cplex ILOG OPL INTERFACE USER S MANUAL 31 Specifying a data source 32 B M 4 In order to generate the Concert model you need to provide data just as you would add a data file in an OPL project along with the model file The simplest way to get data is also to provide a file C IloOplDataSource dataSource env DATADIR mulprod dat opl addDataSource dataSource Java IloOplDataSource dataSource oplF createOplDataSource DATADIR A Moda opl addDataSource dataSource NET Visual Basic snippet_N32324 ILOG OPL INTERFACE USER S MANUAL Generating the Concert model Once you have specified your data source you can generate the Concert model C opl generate Java opl generate NET Visual Basic snippet N32380 This method also loads the model into the engine instance passed earlier IBM ILOG OPL INTERFACE USER S MANUAL 33 Solving the model You can solve the model in the usual way with Concert Technology C if cplex solve Java if cplex solve NET Visual Basic snippet N323F2 34 IBM ILOG OPL INTERFACE USER S MANUAL Accessing the solution You can access the solution directly through OPL or through the Concert API Accessing the solution through OPL 4 Print the OPL solution directly like this C
8. M ee TOS PELOS This is the warehouse OPL model a static String GetModelText String model mode l mode l mode l mode l mode l mode l mode l mode l mode l mode l mode l mode l mode l mode l mode l mode l mode 1 mode l mode l mode l mode l mode l mode l LOG OPL a int fixed ES On tae nbWarehouses OS bae nbStores OO Maa disaggregate assert nbStores gt nbWarehouses range Warehouses 1 nbWarehouses range Stores jm Sites int capacity w in Warehouses nbStores div nbWarehouses w mod nbStores div nbWarehouses int supplyCost s in Stores w in Warehouses 1 s 10 w mod 100 dvar float open Warehouses in 0 1 tavar float supply Stores Warehouses in 0 1 79 minimize sum w in Warehouses fixed open w sum w in Warehouses s in Stores supplyCost s w supply s w LS rra 1 RO RA ab Stones sum w in Warehouses supply s w forall w in Warehouses H sum s in Stores supply s w lt open w capacity w ll w if disaggregate 1 E forall w in Warehouses s in Stores i supply s w lt open w oj Que r NTERFACE USER S MANUAL B return model The code is complete 10 Launch Microsoft Excel with your plug in using the Visual Studio Debug Start Debugging command Excel starts with the new command bar containing OPL Warehouse Setup and O
9. new System IO StringWriter Os try setValue sheet B9 Computing SolveProblem sheet errHandlerErrors SetValue sheet BOF Success r catch Exception ex LOG OPL INTERFACE USER S MANUAL 65 66 B M setValue sheet B9 Error ex ToString Sr an dilema OI SPEO Sender gl ae 1 V private void SolveProblem Excel Worksheet sheet System IO StringWriter errHandlerErrors actually solve the problem with OPL Add some references to the OPL NET APIs used to solve the problem a In the Solution view select the project ExcelWarehouse the References and click Add Reference b In the Add Reference Wizard select Browse navigate to the OPL installation and add lt oPL gt 1ib oplal1 d11 C At the top of the ThisAddIn cs file append the following lines to the using list using ILOG Concert using ILOG CPLEX using ILOG OPL using Exception System Exception Add the code that actually solves the problem using OPL private void SolveProblem Excel Worksheet sheet System 10 StringWriter errHandlerErrors OplFactory DebugMode true OplFactory oplF new OplFactory OplErrorHandler errHandler oplF CreateOplErrorHandler errHandlerErrors OplModelSource modelSource oplF CreateOplModelSourceFromString GetModelText warehouse OplSettings settings oplF CreateOplSettings errHandler plModelDefinition def oplF CreateOplModelDefinition modelSource
10. platforms or LD_LIBRARY_PATH other Unix platforms environment variable lt OPL_dir gt bin lt port_name gt lt format gt It contains the shared libraries Windows d11 and Unix so or a files that applications need to run When you install OPL on Windows this directory is added to the PATH LIBPATH Or LD LIBRARY PATH variable 4 Set your environment variables On Windows make sure that the path lt OPL_dir gt bin lt port_name gt is in your PATH environment variable so that the shared libraries are found On Unix make sure that lt OPL_dir gt bin lt port_name gt is in your LIBPATH or LD LIBRARY PATH environment variable so that the shared libraries are found Note To see the solution in your file you have to force the flush of the output stream using cout endl For more information and examples on how to use Concert Technology as well as the CPLEXG and CP Optimizer APIs for Concert Technology see the Concert CPLEX and CP Optimizer documentation ILOG OPL INTERFACE USER S MANUAL The Java interface Presents the Java API delivered with IBM ILOG OPL For details see the Java API Reference Manual In this section Overview of the Java interface Presents a high level overview of the OPL Java interface Object creation and factories Describes the usage of constructors in the OPL Java interface Memory management Provides information on memory management while using the OPL Java interfac
11. settings o plex cplex oplF CreateCplex plModel opl oplF CreateOplModel def cplex plDataSource dataSource new MyParams oplF sheet pl AddDataSource dataSource p in l Generate cplex Solve Our On Om Ome LOG OPL INTERFACE USER S MANUAL B M setValue sheet B10 opl Cplex ObjValue else setValue sheet B10 No solution oplF End This class feeds data to the OPL model from the appropriate cells of the input Excel worksheet up class MyParams CustomOplDataSource private Excel Worksheet xlDataSheet public MyParams OplFactory oplF Excel Worksheet xlDataSheet base op1F xlDataSheet xlDataSheet public override void CustomRead OplDataHandler handler this DataHandler EY handler StartElement nbWarehouses handler AddIntItem Intl6 Parse getValue xlDataSheet B2 handler EndElement handler StartElement nbStores handler AddIntItem Intl16 Parse getValue xlDataSheet B3 handler EndElement handler StartElement fixed handler AddIntItem Int16 Parse getValue _xlDataSheet B4 handler EndElement handler StartElement disaggregate handler AddIntItem Int16 Parse getValue _xlDataSheet B5 handler EndElement LOG OPL INTERFACE USER S MANUAL 67 68 B M catch Exception ex MessageBox Show Exception in custom data source
12. Route Routes Lagian omite lla ata rocas Lol Sespoerneb alia Robes jhe Sample2 The purpose of Sample2 is to output a multidimensional array x i j to illustrate how arrays and subarrays are managed as shown in Output of a multidimensional array Output of a multidimensional array IloIntMap x opl getElement x asIntMap IloSymbolSet sl opl getElement sl asSymbolSet IloSymbolSet s2 opl getElement s2 asSymbolSet Iterate on the first indexer FORMATOS ymbolsetlterat on SO O Ale Get the second dimension array from the first dimension IloIntMap sub x getSub itl Iterate on the second indexer of x that is the indexer of the subarray for IloSymbolSetIterator it2 s2 it2 ok 1t2 This is the last dimension of the array so you can directly use the get method COURS Wai i th ae e eE LOG OPL INTERFACE USER S MANUAL Sac lt lt UE To access the elements of an array you must first access the sub arrays until the last dimension then you can get the values Here as there are two dimensions you have to get one sub array from which you can directly get the values The array of integers is indexed by two sets of strings The simplified model is Stacey uly Ss oe Stan Ss Aas A SES 2 saad Sample 3 The purpose of sample3 is to output an array of tuples arrayT i to illustrate how tuple elements can be accessed The simplified model is tuple t
13. createOplModel def cplex NET CH NET Specifying the model definition OplFactory DebugMode true OplFactory oplF new OplFactory OplErrorHandler errHandler oplF CreateOplErrorHandler Console QUEJA Cplex cplex oplF CreateCplex OplModelSource modelSource oplF CreateOplModelSourceFromString GetModelText warehouse OplSettings settings oplF CreateOplSettings errHandler IBM ILOG OPL INTERFACE USER S MANUAL 43 44 B M modelSource LOG OPL OplModelDefinition def settings oplF CreateOplModelDefinition OplModel opl oplF CreateOplModel def cplex INTERFACE USER S MANUAL The data 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 4 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 examples below The custom data source is described in Custom data sources C C Specifying a data source Java Java Specifying a data source IloOplDataSource dataSource new MyParams op1F nbWarehouses nbStores fixed disaggregate opl addDataSource dataSource opl generate NET CH NET Specifying a data source OplDataSource dataSource new MyParams oplF nbWarehouses nbStores fixedP disaggregate opl AddDataSource dataSource opl Generate
14. delete on Concert objects or end on OPL objects These methods delete objects before the global cleanup and thus free memory earlier ILOG OPL INTERFACE USER S MANUAL Compatibility with Java CPLEX B M The ilog concert and ilog cplex packages are designed to be compatible with the equivalent packages in IBM ILOG CPLEX This means that they offer the same API slightly extended for OPL although the implementation is quite different The benefit is that you can reuse your existing JConcert Java CPLEX modeling code and combine it with OPL models Because OPL can produce full Concert models and offers a backward compatible API you benefit from a smooth migration path to OPL without losing your previous work Note 1 The CPLEX Java API related to 110LPMatrix which allows direct manipulation of the CPLEX matrix in Java is not available in the OPL implementation 2 Serialization is not supported for JConcert modeling classes 3 CPLEX callbacks are supported with parallel search in Java interfaces ILOG OPL INTERFACE USER S MANUAL 15 Compatibility with CP Optimizer Java interface The Java interface is fully compatible with the CP Optimizer Java interface The ilog cp package shipped with OPL is identical to that shipped with CP Optimizer 16 IBM ILOG OPL INTERFACE USER S MANUAL Deployment of Java applications To compile and build an application that uses OPL Java interfaces you need only one JAR file o
15. objects All the C memory is allocated on an internal heap of the Op1Factory object and cleaned up by a call to the method OPLFactory End The internal heap is an instance of the C class IloEnv Important This means that in most cases you do not need to be concerned with memory management all the memory used by your model is correctly cleaned up at the end Some applications may need tighter control on memory management This is the case for applications to which all of the following apply 4 They demand a lot of memory and 4 They make a lot of incremental model modifications elements are repeatedly added to then removed from the model which is solved after each addition and removal and 4 They are long lived that is the application keeps modifying and re solving the same model over long periods Such applications can explicitly manage memory by calling the method IMPModeler Delete on Concert objects or End on OPL objects These methods delete objects before the global cleanup and thus free memory earlier ILOG OPL INTERFACE USER S MANUAL CPLEX goals IBM ILOG CPLEX provides advanced control on search strategies through user goals that are called during the search This feature is not available for the NET API in this release although it is supported in C and Java It will be supported in a future release However CPLEX callbacks including CPLEX callbacks with parallel search are supported in this
16. objects accessed through OPL elements Availability of Concert objects OPL Element Available after Available a end external data elements read from a data source no yes internal data elements initialized inside the mod file no yes dvar array solution value An array with values of decision variables for no the current solution available by calling the method asIntMap or asNumMap for a dvar array element postprocessing All elements declared for postprocessing mo no When postprocess is called multiple times as when processing intermediate feasible solutions the second call ends the objects created for the first call See these two stock cutting examples lt OPL_dir gt examples opl cutstock cutstock_main mod lt OPL_dir gt examples opl cutstock cutstock_int_main mod where lt OPL_dir gt is your installation directory ILOG OPL INTERFACE USER S MANUAL accessing model through API 36 run configurations through API 36 solutions through API 35 values of decision variables through API 52 API NET 19 C 9 Java 11 assembly file for the OPL NET API 26 C API compiling and linking applications 9 classes TloCP 30 IloCplex 30 35 IloEnv 29 IloOplErrorHandler 29 IloOplFactory 29 loOplModel 31 lloOplModelDefinition 30 loOplModelSource 29 IloOplIProject IloOplRunConfiguration 36 IloOplSettings 30 code samples iterators 54 compiling and building applications NET 26 Java 17 Concert Technology e
17. 5 deployment 17 memory management 14 object creation and factories 13 overview 11 libraries C linking 9 linking C libraries 9 memory allocation and management 70 in NET 22 in Java 14 models accessing data 45 accessing through API 36 creating via API 31 error handling 29 instantiating via API 36 41 model definition 30 43 model source 29 solving via API 34 IBM ILOG OPL INTERFACE object creation in NET 21 in Java 13 oplrun using projects and run configurations 36 postprocessing via APIs 57 projects creating via API 36 run configurations accessing through API 36 setDebugMode method IloOplFactory class 60 settings API to customize OPL behavior 56 settings files and IloOplProject API 37 solutions accessing through API 35 accessing values of decision variables 52 Visual Studio and NET Framework packages 26 Visual Studio Tools for Office 2003 integrating OPL with Excel 62 USER S MANUAL
18. FACE USER S MANUAL 51 Accessing model elements To access any model element by its name Use the method getElement C IloOplElement supply oplModel getElement supply Java IloOplElement supply oplModel getElement supply NET OplElement supply oplModel GetElement supply The 11o0plElement interface offers accessors for all possible element types It is the user s responsibility to pick the right accessor for the type of the elements he has declared For decision variables there are two different types of accessors one to obtain the Concert object itself for this decision variable 4 the other to get the values of decision variables within a solution The latter is available only if a solution has been found The subsequent sections give examples of each for a supply model element To access a decision variable To get the supplyVarl decision variable within a model write the following code C IloNumVarMap supplyVarMap supply asNumVarMap IloNumVar supplyVarl supplyVarMap get 1 Java IloNumVarMap supplyVarMap supply asNumVarMap IloNumVar supplyVarl supplyVarMap get 1 NET INumVarMap supplyVarMap supply AsNumVarMap INumVar supplyVarl supplyVarMap Get 1 To access the values of a decision variable 4 To get the values of the supp1y1 decision variable within a solution write the following code 52 IBM ILOG OPL INTERFACE USER S MANUAL B
19. PL Warehouse Solve a Click the button OPL Warehouse Setup It populates the current sheet with default values for the problem b Edit the values as appropriate C Click the button OPL Warehouse Solve It solves the problem using OPL displaying results in cell B10 425 for the default values ES Microsoft Excel Book1 BEE Sl Ele gdt View Insert Format Tools Data Window Help Type a question For help X DA Ga a z 10 B zr UE A gt rr Data used by the OPL model CED E nbWareho nbStores fixed disaggrege Result computed by the OPL model State Success Objective 425 on M 4 gt nNSheet1 Sheet2 Sheet3 Ready Integrating OPL NET API into an MS Excel worksheet Useful training material on working with VSTO 2005 is available at http msdn2 microsoft com en us library ebax1172 VS 80 aspx M ILOG OPL INTERFACE USER S MANUAL 69 Memory management 70 B M The recommended way to manage memory in Concert applications is to use the method IloEnv end to clear all the memory currently in use If you need more control on the memory used by your OPL objects 11o0p1Model objects offer the method end In the default case after an OPL model instance has been ended all its Concert objects that correspond to data elements are still available After the method ena no objects remain Availability of Concert objects summarizes the availability of Concert
20. REGROUPE eene deni 51 Accessing model clement 2 c cccccceeseccceeeceeeeseeeeseecesesceeeencensneneeneseeesessneeeseneesesceeeeseeaeessneeeeseees 52 Iterating through OPL elements sess nnne nennen restreint 54 Seltil1gS ir tte REM 56 PosiprocessiDg SOlUtlOns s 3 us i25 tese dal ek ots 57 Error handling ar ds rara dee cae cpi ey aee eb ptt en re thecae td 59 Deb g mode 2 1 3 ih E ep A EUR ea ERREUR adi 60 Printirig data to a stream i o epo e EE RR E Do FLEIRE 61 Integrating OPL with Excel using Visual Studio Tools for Office sseeenenene 62 Meinory management 2 ie id ertet in D er E eet n D e i ree et Eee lite uE 70 OA E E E E E 71 4 BM ILOG OPL INTERFACE USER S MANUAL Interfaces User s Manual IBM ILOG OPL Interfaces enable users to integrate OPL models with IBM ILOG Concert They are available in the C Java and NET programming languages This manual provides a tutorial approach to using these application programming interfaces APIs and should be used in conjunction with the Interfaces Reference Manual for the language you are using In this section Introduction Explains how to use the C Java and NET libraries to integrate OPL models with IBM ILOG Concert Technology The introduction to the C Java and NET interfaces stresses the specificities for each language Tutorial Shows how to write basic code to create a simple OPL model fr
21. RFACE USER S MANUAL 19 Overview of the NET interface 20 B M The NET interface offers basically the same functionality as the C one The NET API is split into several namespaces The 110G Concert namespace contains the Concert modeling API for modifying models 4 The IL0G CP namespace contains the CP Optimizer control API for controlling the solving process of constraint programming models The ILOG CPLEX namespace contains the CPLEX control API for controlling the solving process of mathematical programming models The ILOG OPL namespace contains the OPL control API for loading and accessing models This API is available for all the languages supported by the NET platform Examples are provided with OPL for C and Visual Basic The NET API is written as a JNI wrapper on the equivalent C libraries it offers the same functionality as the C API Each call to a method of the API goes through a wrapping layer This may result in a slight performance overhead while the model is created compared to using the C API depending on the number of API function calls Since you call only few API functions to load and solve your model the overhead is negligible in usual cases but it may become important if you use the low level Concert CP Optimizer or CPLEX API for a complete model creation for example constructing a matrix line by line using INumExpr APIs or adding IConstraint objects one by one to a
22. S 2008 example projects contain a post build event specified as mt exe nologo outputresource TargetFileName 1 manifest examples manifest This event is required for C applications compiled with Visual Studio 2005 and 2008 By default all applications built with these versions of Visual Studio are built as isolated applications with a manifest either embedded as a resource or accompanying the final binary as an external file Sometimes the manifest generated automatically is not correct In this case you need to force generation of the right manifest To compile and build an application that uses OPL C interfaces M 1 Include the directory of header files lt OPL_dir gt include 2 Link with the following IBM ILOG libraries Windows libraries Unix libraries except AIX concert lib concert so cp lib cp so cplex version number lib cplex version number so dbkernel lib dbkernel so dbinkdyn lib dbinkdyn so iljs lib iljs so ilocplex lib ilocplex so ilog lib ilog so opl lib opl so These libraries are in the following directory lt OPL_dir gt lib lt port_name gt lt format gt where lt OPL_dir gt is your installation directory AIX libraries concert a cp a cplex lt version_number gt a dbkernel a dbinkdyn a iljs a ilocplex a ilog a opl a ILOG OPL INTERFACE USER S MANUAL 9 10 B M 3 Make sure the following directory is in your PATH on Windows LIBPATH AIX
23. b OPL dir gt examples opl_interfaces dotnet x86_net2005_8 0 CSharp OpIRunSample OpiIRunSample cs where OPL dir is your installation directory Creating the project You can create an 1100p1Project instance directly using a project path C Thog SHINee ja envy Cl eret PISO RJ ere t Pate 1 Java MGOplProjeck pry sopilkicreateOpl Project gel getProjectPbalth s Cit DITA RASO BROS CEN oolit Creates OPINE no ecu elke nO Sc tb SE Accessing a run configuration 4 From that project you can access one of the included run configuration If you pass no argument you get the default run configuration C rc prj makeRunConfiguration cl getRunConfigurationName Java rc prj makeRunConfiguration cl getRunConfigurationName Ci rc prj MakeRunConfiguration cl RunConfigurationName ILOG OPL INTERFACE USER S MANUAL OPL creates the I1o00p1Mode1 instance from the run configuration automatically Accessing the model You can access with the following code C IloOplModel opl rc getOplModel Java IloOplModel opl rc getOplModel C Dim opl As OplModel rc GetOplModel You can then use the 11o0plModel instance as usual Using the 1100p1Project and IloOp1RunConfiguration API brings more than one benefit 4 It is easier to use when intermediate structures are not necessary 4 It enables you to use settings files ops Allthe advantages of run configurations remain available I
24. bar for OPL AddInMenuBar Application CommandBars Add OPL Commands Office MsoBarPosition msoBarTOoDp missing true setup button SetupButton Office CommandBarButton AddInMenuBar Controls Add Office MsoControlType msoControlButton missing missing missing true SetupButton Caption OPL Warehouse Setup SetupButton Style Microsoft Office Core MsoButtonStyle msoButtonCaption SetupButton Click new Office CommandBarButtonEvents ClickEventHandler SetupButton Click solve button BM ILOG OPL INTERFACE USER S MANUAL 63 SolveButton Office CommandBarButton AddInMenuBar Controls Add Office MsoControlType msoControlButton missing missing missing true SolveButton Caption OPL Warehouse Solve SolveButton Style Microsoft Office Core MsoButtonStyle msoButtonCaption SolveButton Click new Office CommandBarButtonEvents ClickEventHandler SolveButton Click AddInMenuBar Visible true catch Exception ex MessageBox Show ex Message ex Source MessageBoxButtons OK MessageBoxIcon lusese gy p private void RemoveOPLCommands SolveButton Delete false SolveButton null SetupButton Delete false SetupButton null AddInMenuBar null private void SolveButton Click Office CommandBarButton Ctrl ref bool CancelDefault respond to solve button click private void SetupButton Click Office CommandBarButton Ctrl ref bool Canc
25. cnnnnnnnnnnnnonnnnnnnnnnnnnonnnnnnnnnnnnnnnnnnananannnos 20 Object creation and factories ics eee e ede rater ie a ena aea re rode dva 21 Memory Manage Menton dci 22 GPEEX goalsz 2 ll ta o o o a ue 23 Compatibility with NET CPLEX 2 i t iia 24 Compatibility with CP Optimizer NET interface ssssssssseseseeeenenenneenn 25 Deployment of NET applications Windows only 26 DIG ees 27 Overview ofthe Tutoriales 2 rre et ct HO EE Hare HS EN esce Lei Me Sad foie cal PE REL ao ie dE EH 28 Creating an OPL Modelo Dn gelten eid 29 Specifying a data SoUrce iiec et Dee eerie pe sU Ine d ee eue sip dise Eee d Bv vea pisco 32 O Copyright IBM Corp 1987 2009 3 Generating the Concert model tnde trece t titi 33 Solving the modelata nosan o tei ee oe mado biie 34 Accessing the sol tlon eat otitis 35 Using run configuration and projects nennen nennen nennen nnne nnne 36 Working with OPL interfaces eeeeeieeeseseeeeeeee seen rr 39 Usirig OPE model instances n canne tenere bosco 41 OVEIVICW n 42 Lhe model definition iR e eee et bcp Sc c PER leone Ra rtu pep Deed 43 Mi A eto deren ath a ee ie aah demie eate teri 45 Setvices On SolUtioris eei oce oe tas fede aep s fn dn eco dt e a et citet 46 Custom data SOU n rem UE GI EB bm un 47 ACCESSING elements e be ef RR ERR ERO REGERE RUBRO
26. culated during preprocessing C IloOplModel printInternalData ostream amp Java IloOplModel printInternalData java io OutputStream outs NET CH OplModel PrintInternalData TextWriter outs IBM ILOG OPL INTERFACE USER S MANUAL 61 Integrating OPL with Excel using Visual Studio Tools for Office 62 B M Since the release of MS Office 2003 Microsoft has been working towards the integration of Office with NET For this purpose Microsoft released a Visual Studio add on named Visual Studio Tools for Office 2003 which allows users to extend MS Office applications with any NET language thus bringing the benefit of the Visual Studio environment and tools to Office development Microsoft has replaced the VSTO 2003 add on with Visual Studio Tools for Office 2005 for basically the same purpose OPL uses this approach to integrate the OPL NET API This is demonstrated by the ExcelWarehouse example This file is at the following location lt OPL_dir gt examples opl_interfaces dotnet x86_ net2005_8 0 ExcelWarehouse where OPL dir is your installation directory The solve process is triggered by a button embedded in the worksheet The input data is taken from the worksheet and the results are written back to the worksheet This walkthrough explains how to create a Microsoft Excel Add in It is coded in C and uses OPL to solve the warehouse problem within Excel 2003 To create a Microsoft Excel Ad
27. d in 1 Install MS Visual Studio 2005 and MS Office 2003 2 Download VSTO 2005 Second Edition from this page http msdn microsoft com en us office aa905543 aspx The downloadable is free if you have VSTO 2005 or VS 2005 Professional Edition VSTO 2005 SE allows you to create Office 2003 and 2007 add ins from Visual Studio 2005 3 Open Visual Studio 2005 and create a new project a Select Visual C Office 2003 Add ins in the New Project Wizard b Name it ExcelWarehouse A new project is created with a dummy add in name ThisAddIn cs namespace ExcelWarehouse public partial class ThisAddIn private void ThisAddIn Startup object sender System EventArgs e lt VSTO generated code gt private void ThisAddIn Shutdown object sender System EventArgs e ILOG OPL INTERFACE USER S MANUAL lt VSTO generated code gt 4 In the ThisAddIn cs file replace the dummy code with the following lines to create anew command bar and buttons for OPL namespace ExcelWarehouse public partial class ThisAddIn private private private private Office CommandBar AddInMenuBar Office CommandBarButton SetupButton Office CommandBarButton SolveButton void ThisAddIn Startup object sender System EventArgs e lt VSTO generated code gt CreateOPLCommands private void ThisAddIn Shutdown object sender System EventArgs e RemoveOPLCommands private void CreateOPLCommands EEY new command
28. d trademarks and logos are trademarks of Sun Microsystems Inc in the United States other countries or both Other company product or service names may be trademarks or service marks of others Acknowledgement The language manuals are based on and include substantial material from The OPL Optimization Programming Language by Pascal Van Hentenryck 1999 Massachusetts Institute of Technology Table of contents Interfaces User s Manual occcccccccnonnccnnccnnnnccononononccnnnononnannnnnnnnnnnn nn nn nr nnn nn nena 5 e A ES 7 About the Interfaces User s Manual ccccsessssssnseececeeeeeeeeeeeeeeeesesessssseeseeseessaeasaeaeeeeeeeeeeeeeeseeeesesesseeeseees 8 Using the G Interface ecco ec cates ce t aene diee per ae tede cet aera peres qd 9 he Java Interfaces omm PEN M EUREN Ie DIEI ME ssi 11 Overview of the Java interface ccccooccoccconccoccnncononoonnnnnonnoonnnnncnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnos 12 Object creation and factories sieniin aaa E nnne nnne nnne nnne rearme 13 Memory Management maroc arte 14 GCompatibility with Java CPLEX innn a ete Bee fi 15 Compatibility with CP Optimizer Java interface sessssseeneeeennennneennen nnns 16 Deployment of Java applicatiONS oonoccnnnicnnnicannoncncnnonncnnnncnn non nnnnnnn nn nano enne nnne 17 The NE TInterface immessi 19 Overview of the NET interface ccoooooonccnncocccnnccnonoonnnnnnnnoonnnnn
29. del the overhead is negligible in usual cases but it may become important if you use the low level Concert CP Optimizer or CPLEX API for a complete model creation for example constructing a matrix line by line using IloNumExpr APIs or adding IloConstraint objects one by one to an IloModel using the API It is therefore recommended to use the OPL language to model your problems whenever possible and use only the low level Concert APIs for the parts that need it runtime additions etc Once created the model is still solved fully in C so there is no loss of performance when solving models whatever language you choose ILOG OPL INTERFACE USER S MANUAL Object creation and factories B The C API allows you to create objects using a constructor To provide greater flexibility and allow for evolution the Java API uses a Factory pattern objects are created by calls to the methods of a root object For example you create OPL objects using the methods of the class IloOPLFactory createOPLModel IloOPLFactory createCPLEX and so on Similarly you create Concert modeling constructs using the methods of the class 11oMPModeler implemented by the TloCplex class numVar range minimize and so on For example the following code lines create an instance of 11oNumVar IloMPModeler modeler new IloCplex IloNumVar var modeler numVar 0 10 The Concert C modeling API works by redefining operators to provide a compact notati
30. e Compatibility with Java CPLEX Describes the relationship of the ilog concert and ilog cplex packages with their equivalent packages in IBM ILOG CPLEXO Compatibility with CP Optimizer Java interface The Java interface is fully compatible with the CP Optimizer Java interface Deployment of Java applications Provides information on how to deploy an application that uses the OPL Java interface M ILOG OPL INTERFACE USER S MANUAL 11 Overview of the Java interface 12 B M The Java interface offers basically the same functionality as the C one The Java API is split into several packages The ilog concert package contains the Concert modeling API for modifying models 4 The ilog cp package contains the CP Optimizer control API for controlling the solving process of constraint programming models 4 The ilog cplex package contains the CPLEX control API for controlling the solving process of mathematical programming models 4 The ilog op1 package contains the OPL control API for loading and accessing models The Java API is written as a JNI wrapper on the equivalent C libraries it offers the same functionality as the C API Each call to a method of the API goes through a wrapping layer This may result in a slight performance overhead while the model is created compared to using the C API depending on the number of API function calls Since you call only few API functions to load and solve your mo
31. e op1a11 d11 located in OPL_dir lib Microsoft NET Framework Version 2 0 Redistributable Package This package is included in Microsoft Visual Studio You can also download it for free from http www msdn microsoft com netframework The appropriate version of Visual Studio is VS2005 for NET2 0 ILOG OPL INTERFACE USER S MANUAL Tutorial Shows how to write basic code to create a simple OPL model from a model definition file and a model data file The model is solved using CPLEX through the Concert API Each step is illustrated by a code sample in each language In this section Overview of the Tutorial Reviews the design principles of the OPL APIs where to locate the libraries and their respective code samples in the distribution and presents the different sections of this tutorial Creating an OPL model Shows how to create an OPL model that utilizes the OPL interfaces Specifying a data source Shows how to specify the data source for your OPL model Generating the Concert model Describes how to generate the Concert model for your OPL model Solving the model Shows how to solve your model Accessing the solution Provides information on how to access the solution through OPL and through Concert Using run configuration and projects Shows how to use run configurations to create the project and access the run configuration and the model using Concert IBM ILOG OPL INTERFACE USER S MANUAL 27 Overview of the Tutor
32. e interfaces are available in the C Java and NET programming languages Each of these application programming interfaces APIs is documented in the Interfaces Reference Manual for that language accessible from the table of contents Before you start Before reading this manual we recommend that you read the part about Languages and APIs in the CPLEX User s Manual which presents IBM ILOG Concert for the various programming languages IBM ILOG Concert is used by both solving engines CPLEX and CP Optimizer Also make sure you read How to read the OPL documentation for details of prerequisites conventions documentation formats and other general information When to use the API The recommended approach to modeling and solving a problem is to start with the IBM ILOG OPL IDE Later you may wish to use an API to extend your model Design principles The design principles for the OPL interfaces are 4 separate the model from the solver 4 instantiate the same OPL model with different data 4 allow Concert to access and modify the model 4 provide data easily 4 access data and results ILOG OPL INTERFACE USER S MANUAL Using the C interface B The C API of OPL is based on the C Concert Technology on the CPLEX C API and on the CP Optimizer API which are themselves based on Concert Technology For more information see the Concert Reference Manual Important Microsoft limitation The C OPL API VS 2005 and V
33. elDefault respond to setup button click 5 Add some utility methods to get set values in cells Static private void setValue Excel Worksheet sheet String cell String value 64 IBM ILOG OPL INTERFACE USER S MANUAL B M 6 7 sheet get_Range cell cell set_Value Excel XlRangeValueDataType xlRangeValueDefault value static private String getValue Excel Worksheet sheet String cell Bt Une Sting ShostagotmRancge celkll cc me Add the code for the Setup button to populate the current Excel sheet private void SetupButton Click Office CommandBarButton Ctrl ref bool CancelDefault Excel Worksheet sheet Excel Worksheet this Application ActiveWorkbook ActiveSheet setValue sheet Al Data used by the OPL model setValue sheet A2 nbWarehouses Setyalvre Sldieeie SU MEE setValue sheet A3 nbStores Sue Wels shee SO lO setValue sheet A4 fixed SetValue she BS e setValue sheet A5 disaggregate setvalue shest Bor le setValue sheet A8 Result computed by the OPL model setvalue sheet A9 States setValue sheet A10 Objective Add the code for the Solve button to launch the OPL solve process private void SolveButton Click Office CommandBarButton Ctrl ref bool CancelDefault Excel Worksheet sheet Excel Worksheet this Application ActiveWorkbook ActiveSheet System IO StringWriter errHandlerErrors
34. ial 28 B M The IBM ILOG OPL Interfaces library enables users to integrate OPL modeling with IBM ILOG Concert Technology These interfaces are designed to fulfill several goals chiefly separate the model from the data separate the modeling phase from the solving phase 4 4 4 instantiate the same OPL model definition with different data embed with IBM ILOG Concert Technology 4 provide custom data easily OPL Interfaces are available in C Java and NET See Introduction for a general presentation of the Interfaces in the three languages See also the Interfaces Reference Manuals in lt OPL_dir gt doc html en US refcppopl index html lt OPL_dir gt doc html en US refjavaopl index html lt OPL_dir gt doc chm index chm where OPL dir is your installation directory Most of the code snippets used in this tutorial are extracted from the mulprod example which exists in all four languages at the following locations lt OPL_dir gt examples opl_interfaces cpp src mulprod cpp lt OPL_dir gt examples opl_interfaces java mulprod src mulprod Mulprod java lt OPL_dir gt examples opl_interfaces dotnet x86_ net2005_8 0 VisualBasic Mulprod Mulprod vb lt OPL_dir gt examples opl_interfaces dotnet x86_ net2005_8 0 CSharp Mullprod Mulprod cs A general presentation of the code samples is provided in Interfaces examples in the Language and Interfaces Samples manual In this tutorial the NET code samples from Mulprod vb a
35. n IModel using the API It is therefore recommended to use the OPL language to model your problems whenever possible and use only the low level Concert APIs for the parts that need it runtime additions etc l Note The NET API requires the vjslib d11 library ILOG OPL INTERFACE USER S MANUAL Object creation and factories The C API allows you to create objects using a constructor To provide greater flexibility and allow for evolution the NET API uses a Factory pattern objects are created by calls to the methods of a root object For example you create OPL objects using the methods of OPLFactory CreateOPLModel OPLFactory CreateCPLEX and so on Similarly you create Concert modeling constructs using the methods of IMPModeler implemented by the cplex class NumVar Range Minimize and so on The Concert C modeling API works by redefining operators to provide a compact notation for common constructs In NET the equivalent constructs are created through regular methods of IModeler Ge Eq Prod and so on IBM ILOG OPL INTERFACE USER S MANUAL 21 Memory management 22 B M The NET CLR garbage collector usually takes care of the memory allocated by NET objects However since the OPL NET API allocates memory in C as well the memory management is slightly different When you use the OPL NET API the first object you create is always the OPL factory Then you use the OPL factory to create all other
36. n particular it is possible to easily run the same model with different setting files or with different data sets IBM ILOG OPL INTERFACE USER S MANUAL 37 38 B M ILOG OPL INTERFACE USER S MANUAL Working with OPL interfaces Explains in more general terms how to work with the OPL C Java and NET Interfaces This section is also illustrated by code samples for each language In this section Using OPL model instances Explains how to instantiate OPL models using a model definition data and a solving engine Services on solutions Mentions additional services available through the 1100p1Mode1 instance as soon as a solution is available Custom data sources Describes how to provide custom data sources for your model by extending the class Ilo0plDataSourceBasell Accessing elements Describes what APIs to use to access model elements such as decision variables and their values and to iterate through model elements Settings Describes the various Settings options available to customize the behavior of OPL Postprocessing solutions Shows how to initiate the call to postprocessing in your model Error handling Describes how to handle messages and integrate them with your environment IBM ILOG OPL INTERFACE USER S MANUAL 39 40 B M Debug mode Explains how to work with your model in debug mode Printing data to a stream Shows how to print your data to a stream using the dat file syntax Integrati
37. ng OPL with Excel using Visual Studio Tools for Office Explains how to create a Microsoft Excel Add in It is coded in C and uses OPL to solve the warehouse problem within Excel 2003 Memory management Provides recommendations to manage memory in Concert applications ILOG OPL INTERFACE USER S MANUAL Using OPL model instances Explains how to instantiate OPL models using a model definition data and a solving engine In this section Overview Presents basic information about working with OPL model instances The model definition Shows how to specify a model definition that can then be used to instantiate one or more models The data Shows how to specify the data source for your model IBM ILOG OPL INTERFACE USER S MANUAL 41 Overview To instantiate an OPL model you need its definition and data as well as an engine that will solve the model Most of the code samples used in this topic are extracted for each language from the warehouse example which exists in all four languages at the following locations lt OPL_dir gt examples opl_interfaces cpp src warehouse cpp lt OPL_dir gt examples opl_interfaces java warehouse src warehouse Warehouse java lt OPL_dir gt examples opl_interfaces dotnet x86_ net2005_8 0 VisualBasic Warehouse Warehouse vb lt OPL_dir gt examples opl_interfaces dotnet x86_ net2005_8 0 CSharp Warehouse Warehouse cs where lt OPL_dir gt is your installation directory A general presentati
38. nvironment 29 generate model 33 cplex model instance used by more than one model 45 custom data sources 47 initializing 47 O Copyright IBM Corp 1987 2009 Index CustomOplDataSource class initializing 47 data accessed by the model 45 printing to a stream 61 data elements iterators 54 data sources adding via API 32 custom 47 debug mode 60 decision variables accessing values within a solution 52 deployment NET API 26 Java API 17 end method IloEnv class 70 loOplModel class 70 environment variables 9 environment instance of for model objects 29 error handling with APIs 59 Excel integration using Visual Studio Tools for Office 2003 62 factories in NET 21 in Java 13 files ops 37 garbage collector NET 22 Java 14 71 72 getDataHandler method IloOplDataSourceBasel class 47 getElement method IloOplDataSourceBasel class 52 TloCP class 30 IloCplex class 30 35 IloEnv class 29 end method 70 IloOplDataHandlerl interface 47 IloOplDataSourceBasel class 47 getDataHandler method 47 getElement method 52 IloOplErrorHandler class 29 IloOplErrorHandlerBasel class 59 IloOplFactory class 29 setDebugMode method 60 IloOpIModel class 31 42 46 61 end method 70 IloOplModelDefinition class 30 IloOplModelSource class 29 IloOplProject class 36 IloOplRunConfiguration class 36 IloOpiSettings class 30 56 interfaces NET 19 C 9 Java 11 iterator example 54 Java API compatibility with Java CPLEX 1
39. od IloOpiFactory setDebugMode When the default mode is on a warning message prints to the console The message is disabled when you turn the debug mode off You can disable the message while still running in debug mode by a call to the method IloOplFactory setDebugModeWarning false To turn off the warning call the method IloOplFactory setDebugModeWarning false or OplFactory DebugModeWarning false before the 11o0plFactory or OplFactory constructor is called IloOplFactory setDebugModeWarning false IloOplFactory oplF new IloOplFactory IloOplErrorHandler errHandler oplF createOplErrorHandler The same applies if you work with NET interfaces ILOG OPL INTERFACE USER S MANUAL Printing data to a stream As an additional service for testing and debugging the class 1100p1Mode1 offers the possibility to print all the data to a stream using the dat file syntax C IloOplModel printExternalData ostream amp Java IloOplModel printExternalData java io OutputStream outs NET C OplModel PrintExternalData TextWriter outs If your model uses data from various sources like databases spreadsheets or custom sources you will be able to write this data to one single file which makes it easier to read This file can be used as a data source for other model instances For debugging purposes you can visualize intermediate data that is the data that is not provided by data sources but cal
40. om a model definition file and a model data file The model is solved using CPLEX through the Concert API Each step is illustrated by a code sample in each language Working with OPL interfaces Explains in more general terms how to work with the OPL C Java and NET Interfaces This section is also illustrated by code samples for each language O Copyright IBM Corp 1987 2009 5 IBM ILOG OPL INTERFACE USER S MANUAL B Introduction Explains how to use the C Java and NET libraries to integrate OPL models with IBM ILOG Concert Technology The introduction to the C Java and NET interfaces stresses the specificities for each language In this section About the Interfaces User s Manual Provides a short overview of the purpose of the OPL interfaces the design principles underlying them and material you should read before using this manual Using the C interface Explains how to compile and build an application that uses OPL C interfaces For details see the C API Reference Manual The Java interface Presents the Java API delivered with IBM ILOG OPL For details see the Java API Reference Manual The NET interface Presents the NET API delivered with IBM ILOG OPL For details see the NET API Reference Manual M ILOG OPL INTERFACE USER S MANUAL 7 About the Interfaces User s Manual 8 B M IBM ILOG OPL Interfaces enable users to integrate OPL models with IBM ILOG Concert Thes
41. on for common constructs In Java the equivalent constructs are created through regular methods of 11oModeler ge eq prod and so on M ILOG OPL INTERFACE USER S MANUAL 13 Memory management 14 B M The Java garbage collector usually takes care of the memory allocated by Java objects However since the OPL Java API allocates memory in C as well the memory management is slightly different When you use the OPL Java API the first object you create is always the OPL factory Then you use the OPL factory to create all other objects All the C memory is allocated on an internal heap of the IloOp1Factory object and cleaned up by a call to the method I1o0PLFactory end The internal heap is an instance of the C class IloEnv Important This means that in most cases you do not need to be concerned with memory management all the memory used by your model is correctly cleaned up at the end Some applications may need tighter control on memory management This is the case for applications to which all of the following applies 4 They demand a lot of memory and 4 They make a lot of incremental model modifications elements are repeatedly added to then removed from the model which is solved after each addition or removal and 4 They are long lived that is the application keeps modifying and re solving the same model over long periods Such applications can explicitly manage memory by calling the method 11oMPModeler
42. on of the code samples is provided in Interfaces examples in the Language and Interfaces Samples manual In this chapter the NET code samples from Warehouse cs are written in C The instructions that cannot be illustrated in each language are given by default in C 42 IBM ILOG OPL INTERFACE USER S MANUAL The model definition The model source provides the text to interpret An error handler is necessary to report errors and warnings during the translation of the model text Later you can use the same model definition to instantiate one or more models C C Specifying the model definition Na enn Ea cut elias Exa p NT IloEnv env intesbaetus AT ae M IloCplex cplex env IloOplErrorHandler handler env cout std istringstream in getModelText IloOplModelSource modelSource env in warehouse IloOplSettings settings env handler IloOplModelDefinition def modelSource settings IloOplModel opl def cplex Java Java Specifying the model definition loOplFactory setDebugMode true loOplFactory oplF new IloOplFactory IloOplErrorHandler errHandler oplF createOplErrorHandler System out loCplex cplex oplF createCplex loOplModelSource modelSource oplF createOplModelSourceFromString getModelText warehouse loOplSettings settings oplF createOplSettings errHandler loOplModelDefinition def oplF createOplModelDefinition modelSource settings loOplModel opl oplF
43. pla11 jar located in lt OPL_dir gt lib This JAR file uses the dynamic library bin lt port_name gt opl lt version gt d1i on Windows or bin lt port_name gt opl lt version gt so on UNIX at run time The OPL Java API supports the JDK from version 5 0 on Windows and UNIX Make sure your CLASSPATH variable includes lt OPL_dir gt lib oplall jar See also AIX platforms in Working Environment for limitations IBM ILOG OPL INTERFACE USER S MANUAL 17 18 B M ILOG OPL INTERFACE USER S MANUAL The NET interface Presents the NET API delivered with IBM ILOG OPL For details see the NET API Reference Manual In this section Overview of the NET interface Presents a high level overview of the OPL NET interface Object creation and factories Describes the usage of constructors in the OPL NET interface Memory management Provides information on memory management while using the OPL NET interface CPLEX goals Describes how the NET API handles search strategies on CPLEX goals Compatibility with NET CPLEX Describes the relationship of the ILOG Concert and ILOG CPLEX namespaces with their equivalent packages in ILOG CPLEX Compatibility with CP Optimizer NET interface The NET interface is fully compatible with the CP Optimizer NET interface Deployment of NET applications Windows only Provides information on how to deploy an application that uses the OPL NET interface M ILOG OPL INTE
44. re written in Visual Basic The instructions that cannot be illustrated in each language are given by default in C This tutorial walks you through the procedures ILOG OPL INTERFACE USER S MANUAL Creating an OPL model To create an OPL model using the IBM ILOG OPL Interfaces library you need 1 To create the Concert environment To create the error handler in the environment To identify the model source To identify the model definition 9 RON To create the engine instance 6 To create the OPL model These steps are explained in this topic To create the Concert environment As for any IBM ILOG Concert Technology model you need an instance of the environment in which to create your model objects Write the following code C IloEnv env Java IloOplFactory oplF new IloOplFactory NET Visual Basic Dim oplF As OplFactory New OplFactory To create the error handler 4 Create an error handler is necessary in the environment to report errors and warnings during the translation of the model text C IloOplErrorHandler handler env cout Java IloOplErrorHandler errHandler oplF createOplErrorHandler NET Visual Basic Dim errorHandler As OplErrorHandler oplF CreateOplErrorHandler To identify the model source 4 Pass the model source that provides the text to interpret IBM ILOG OPL INTERFACE USER S MANUAL 29 C IloOplModelSource modelSource env DATADIR mulprod mod
45. release of OPL IBM ILOG OPL INTERFACE USER S MANUAL 23 Compatibility with NET CPLEX 24 B M The ILOG Concert and ILOG CPLEX namespaces are designed to be compatible with the equivalent namespaces in IBM ILOG CPLEX This means that they offer the same API slightly extended for OPL although the implementation is quite different The benefit is that you can reuse your existing Concert NET or CPLEX NET modeling code and combine it with OPL models Because OPL can produce full Concert models and offers backward compatible APIs you benefit from a smooth migration path to OPL without losing your previous work Note The CPLEX NET API related to ILPMatrix which allows direct manipulation of the CPLEX matrix in NET is not available in the OPL implementation ILOG OPL INTERFACE USER S MANUAL Compatibility with CP Optimizer NET interface The NET interface is fully compatible with the CP Optimizer NET interface The IBMO ILOG CP NET API shipped with OPL is identical to that shipped with CP Optimizer IBM ILOG OPL INTERFACE USER S MANUAL 25 Deployment of NET applications Windows only 26 B M The NET API is provided as the assembly file 11b op1a11 d411 which uses the dynamic library bin opl version number dotnet dll at run time The OPL NET API supports version 2 0 of NET Framework More specifically to compile and build an application that uses OPL NET interfaces you need one DLL fil
46. s _fixed fixed _disaggregate disaggregate public void customRead IloOplDataHandler handler getDataHandler handler startElement nbWarehouses handler addIntItem _nbWarehouses handler endElement handler startElement nbStores handler addIntItem nbStores handler endElement handler startElement fixed handler addIntItem fixed handler endElement handler startElement disaggregate handler addIntItem disaggregate handler endElement LOG OPL INTERFACE USER S MANUAL B NET CH Accessing the values a decision variable within a solution M internal class MyParams LOG CustomOplDataSource int nbWarehouses int nbStores mte sexed int disaggregate internal MyParams OplFactory oplF int nbWarehouses int nbStores int fixedP int disaggregate OPL base oplF nbWarehouses nbWarehouses _nbStores nbStores mete die Soi _disaggregate disaggregate NTERFACE USER S MANUAL 49 50 B M ILOG OPL INTERFACE USER S MANUAL Accessing elements Describes what APIs to use to access model elements such as decision variables and their values and to iterate through model elements In this section Accessing model elements Shows how to access the elements of your model Iterating through OPL elements Shows how to iterate through the elements of your model IBM ILOG OPL INTER
47. ution Console Out status 0 else Console Out WriteLine No solution status 1 IBM ILOG OPL INTERFACE USER S MANUAL 57 58 B M ILOG OPL oplF End INTERFACE USER S MANUAL Error handling B To better integrate messages with your environment you may choose to handle them yourself This is possible by extending the class ITloOplErrorHandlerBasel You can override the virtual methods to report messages IloBool handleError IloBool handleWarning IloBool handleFatal These methods return a value to indicate whether the messages were handled correctly or not If a message could not be handled an exception is thrown It is not possible to extend the class 11o0plErrorHandler in Java and NET However you can redirect the error messages to any stream by using the appropriate factory methods Java IloOplFactory createOplErrorHandler java io OutputStream outs NET CH OplFactory CreateOplErrorHandler TextWriter outs M ILOG OPL INTERFACE USER S MANUAL 59 Debug mode 60 B M By default the debug mode is on It is a good practice to keep it on while you develop your application because it helps you diagnose problems In particular you need to have it on if you experience a core dump when running Java code However the debug mode slows down your application You should therefore make sure you turn it off when you release your application To do this use the meth
48. xedArray For i To NUMDEMAND handler SetItemStringIndex dtin Rows i 1 0 handler StartIndexedArray For j 1 To NUMSUPPLY handler SetItemStringIndex dtin Columns j ColumnName handler AddNumItem dtin Rows i 1 3 Next j handler EndIndexedArray Next i handler EndIndexedArray handler EndElement Initialization of a string set custom data source handler StartElement Plants handler StartSet For j 1 To NUMSUPPLY handler AddStringItem dtin Columns j ColumnName Next j handler EndSet handler EndElement C C Providing custom data sources void MyParams read const IloOplDataHandler handler getDataHandler handler startElement nbWarehouses handler addIntItem _nbWarehouses handler endElement handler startElement nbStores handler addIntItem _nbStores handler endElement IBM ILOG OPL INTERFACE USER S MANUAL 47 48 B M handler startElement fixed handler addIntItem fixed handler endElement handler startElement disaggregate handler addIntItem disaggregate handler endElement Java Java Providing custom data sources static class MyParams extends IloCustomOplDataSource int _nbWarehouses int _nbStores int fixed int disaggregate MyParams IloOplFactory oplF int nbWarehouses int nbStores int fixed int disaggregate super oplF _nbWarehouses nbWarehouses _nbStores nbStore
Download Pdf Manuals
Related Search
Related Contents
Manuel de L`utilisateur Débitmètre pédiatrique PreciseR ™ de CO2-mètre cabrio-toit-retractable EDA-PDA Barcode Reader Symbol 8800 - User Guide notice - Detecteurs.fr 2014年度(PDF/612KB Copyright © All rights reserved.
Failed to retrieve file