Originally posted by: SystemAdmin
[Myke said:]
Hi Alain,
I saw your post and it seems you can help me.
I'm currently developing a system that will run my OPL model from the .NET program.
My .NET program only takes input and insert it to the database.
The model then will get the data from database and put the result output in another table.
My problem is when I run the OPL model from the OPL IDE i get the results out on the database but when I try running my .NET code It doesn't show the results in the database.
The code Im running to call the model to solve
Private Sub Testing()
Try
OplFactory.DebugMode = True
Dim oplF As OplFactory = New OplFactory
Dim rc0 As OplRunConfiguration = oplF.CreateOplRunConfiguration(DATADIR + "/Testing 1.mod", DATADIR + "/Testing.dat")
rc0.GetOplModel().Generate()
If (rc0.Cplex.Solve = True) Then
Response.Write("
Solution found")
Response.Write("OBJECTIVE : " & rc0.Cplex.ObjValue)
Else
Response.Write("No Solution!")
End If
rc0.End()
oplF.End()
Catch ex As ILOG.Concert.Exception
Response.Write(ex.Message)
End Try
End Sub
//Testing 1.mod
{string} Products = ...;
{string} Resources = ...;
int NbPeriods = ...;
range Periods = 1..NbPeriods;
float Consumption[Resources][Products] = ...;
float Capacity[Resources] = ...;
float Demand[Products][Periods] = ...;
float InsideCost[Products] = ...;
float OutsideCost[Products] = ...;
float Inventory[Products] = ...;
float InvCost[Products] = ...;
dvar float+ Inside[Products][Periods];
dvar float+ Outside[Products][Periods];
dvar float+ Inv[Products][0..NbPeriods];
minimize
sum( p in Products, t in Periods )
(InsideCost[p]*Inside[p][t] +
OutsideCost[p]*Outside[p][t] +
InvCost[p]*Inv[p][t]);
subject to {
forall( r in Resources, t in Periods )
ctCapacity:
sum( p in Products )
Consumption[r][p] * Inside[p][t] <= Capacity[r];<br /> forall( p in Products , t in Periods )
ctDemand:
Inv[p][t-1] + Inside[p][t] + Outside[p][t] == Demand[p][t] + Inv[p][t];
forall( p in Products )
ctInventory:
Inv[p][0] == Inventory[p];
};
tuple plan {
string product;
int period;
float inside;
float outside;
float inv;
}
{plan} Plan = { <p,t,Inside[p][t],Outside[p][t],Inv[p][t]>| p in Products, t in Periods};
//Testing.dat
DBconnection source("odbc","DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\\FOR MYKE\\MultiprodDB.mdb//");
Products from DBread(source, "SELECT Products FROM Products");
Resources from DBread(source, "SELECT Resources FROM Resources");
NbPeriods = 3;
Consumption = [
[ 0.5, 0.4, 0.3 ],
[ 0.2, 0.4, 0.6 ]
];
Capacity = [ 20, 40 ];
Demand = [
[ 10 100 50 ]
[ 20 200 100]
[ 50 100 100]
];
Inventory = [ 0 0 0];
InvCost = [ 0.1 0.2 0.1];
InsideCost = [ 0.4, 0.6, 0.1 ];
OutsideCost = [ 0.8, 0.9, 0.4 ];
DBExecute(source,"drop table Plan");
DBExecute(source,"create table Plan(product varchar(15), period varchar(10), inside real, outside real, inv real)");
Plan to DBUpdate(source,"INSERT INTO Plan(product, period, inside, outside, inv) VALUES(?,?,?,?,?)");
#DecisionOptimization#OPLusingCPLEXOptimizer