Originally posted by: SystemAdmin
[alain.chabrier said:]
Hi,
here is an updated program that works for me (I join my dummet mod and dat too) :
Dim counter As Integer
For counter = 1 To 50
Dim oplF As OplFactory = New OplFactory
Dim errHandler As OplErrorHandler = oplF.CreateOplErrorHandler(Console.Out)
OplFactory.DebugMode = True
Dim masterCp As CP = oplF.CreateCP
Dim Modelsource As OplModelSource = oplF.CreateOplModelSource("C:\temp\MyModel.mod")
Dim datasource As OplDataSource = oplF.CreateOplDataSource("C:\temp\MyData.dat")
Dim setting1 As OplSettings = oplF.CreateOplSettings(errHandler)
Dim def As OplModelDefinition = oplF.CreateOplModelDefinition(Modelsource, setting1)
Dim opl As OplModel = oplF.CreateOplModel(def, masterCp)
REM opl.AddDataSource(datasource)
REM Dim CpDataElements As OplDataElements = opl.MakeDataElements
Dim CpDataElements As OplDataElements = oplF.CreateOplDataElements()
REM CpDataElements.SetElement(CpDataElements.MakeElement("coverTrip", counter))
CpDataElements.AddElement(CpDataElements.MakeElement("coverTrip", counter))
opl.AddDataSource(CpDataElements)
opl.Generate()
MsgBox(CpDataElements.GetElement("coverTrip").AsInt)
MsgBox(opl.GetElement("coverTrip").AsInt)
If masterCp.Solve Then
opl.PrintSolution(Console.Out)
End If
oplF.End()
My .mod :
using CP;
int coverTrip = ...;
My .dat
coverTrip = 10;
(this .dat is not used at all, as in my case, all the data is given by DataElements, in your case, you have to add 2 datasource, one form file, and one from calculated data.) If I keep the adddataSource call I hget a correct errir aboiut having coverTrip defined twice.
If I use
opl.MakeDataElements
then I force opl to generate, and hence alre4ady evaluate coverTrip from the data source.
here, I just want an empty DataElements, I create it from the factory.
hope this helps,
if you have more problem, you can send your complete .modt and .dat
Alain
#DecisionOptimization#OPLusingCPOptimizer