i still confused to parameterize solver foundation.
take a look at
http://blogs.msdn.com/b/natbr/archive/2009/05/05/creating-parameterized-solver-foundation-models-using-linq-to-sql.aspx[
^]
i successfully try that tutorial but i can't use it to my case.
i will review what that web did.
this is normal case :
void newSample1()
{
SolverContext context = SolverContext.GetContext();
context.ClearModel();
Model model = context.CreateModel();
Decision sa = new Decision(Domain.RealRange(0, 9000), "SA");
Decision vz = new Decision(Domain.RealRange(0, 6000), "VZ");
model.AddDecisions(sa, vz);
model.AddConstraint("demand1", 0.3 * sa + 0.4 * vz >= 1900);
model.AddConstraint("demand2", 0.4 * sa + 0.2 * vz >= 1500);
model.AddConstraint("demand3", 0.2 * sa + 0.3 * vz >= 500);
model.AddGoal("goal", GoalKind.Minimize, 20 * sa + 15 * vz);
Solution solution = context.Solve(new SimplexDirective());
Report report = solution.GetReport();
Console.WriteLine(report);
Console.ReadLine();
}
private static void LinqDataBinding()
{
SolverContext context = SolverContext.GetContext();
context.ClearModel();
Model model = context.CreateModel();
NortwindDataContext db = new NortwindDataContext();
Set Product1set = new Set(Domain.Any, "Product1s");
Set countries = new Set(Domain.Any, "countries");
Parameter demand = new Parameter(Domain.Real, "demand", Product1set);
demand.SetBinding(db.Products, "Demand","ProductId");
Parameter yield = new Parameter(Domain.Real, "yield", Product1set, countries);
yield.SetBinding(db.yields,"Yieldc", "ProductId","CountryId");
Parameter limit = new Parameter(Domain.Real, "limit", countries);
limit.SetBinding(db.countries, "limit", "CountryId");
Parameter cost = new Parameter(Domain.Real, "cost", countries);
cost.SetBinding(db.countrycosts,"cost", "CountryId" );
model.AddParameters(demand, yield, limit, cost);
Decision produce = new Decision(Domain.RealNonnegative, "produce", countries);
model.AddDecision(produce);
model.AddConstraint("Demand",
Model.ForEach(Product1set, p => Model.Sum(Model.ForEach(countries, c => yield[p, c] * produce[c])) >= demand[p]));
model.AddConstraint("ProductionLimit",
Model.ForEach(countries, c => produce[c] <= limit[c]));
model.AddGoal("goal", GoalKind.Minimize, Model.Sum(Model.ForEach(countries, c => cost[c] * produce[c])));
Solution solution = context.Solve(new SimplexDirective());
Report report = solution.GetReport();
Console.WriteLine(report);
Console.ReadLine();
}
this is my case, i succefully implement normal case..
structure db & data sample :
https://drive.google.com/file/d/0B12-kOJbFzA0QTYxaTZ1TWFGeWs/edit?usp=sharing[
^]
https://drive.google.com/file/d/0B12-kOJbFzA0TXZOX2loUktmRHM/edit?usp=sharing[
^]
void sampleExcel()
{
SolverContext context = SolverContext.GetContext();
Model model = context.CreateModel();
Decision djakartaMJO = new Decision(Domain.RealNonnegative, "djakartaMJO");
Decision djakartaUNG = new Decision(Domain.RealNonnegative, "djakartaUNG");
Decision djakartaCBT = new Decision(Domain.RealNonnegative, "djakartaCBT");
Decision dbandungMJO = new Decision(Domain.IntegerNonnegative, "dbandungMJO");
Decision dbandungUNG = new Decision(Domain.IntegerNonnegative, "dbandungUNG");
Decision dbandungCBT = new Decision(Domain.IntegerNonnegative, "dbandungCBT");
Decision ddenpasarMJO = new Decision(Domain.IntegerNonnegative, "ddenpasarMJO");
Decision ddenpasarUNG = new Decision(Domain.IntegerNonnegative, "ddenpasarUNG");
Decision ddenpasarCBT = new Decision(Domain.IntegerNonnegative, "ddenpasarCBT");
Decision dlampungMJO = new Decision(Domain.IntegerNonnegative, "dlampungMJO");
Decision dlampungUNG = new Decision(Domain.IntegerNonnegative, "dlampungUNG");
Decision dlampungCBT = new Decision(Domain.IntegerNonnegative, "dlampungCBT");
Decision dmedanMJO = new Decision(Domain.IntegerNonnegative, "dmedanMJO");
Decision dmedanUNG = new Decision(Domain.IntegerNonnegative, "dmedanUNG");
Decision dmedanCBT = new Decision(Domain.IntegerNonnegative, "dmedanCBT");
model.AddDecisions(djakartaMJO, djakartaUNG, djakartaCBT, dbandungMJO, dbandungUNG, dbandungCBT, ddenpasarCBT, ddenpasarMJO, ddenpasarUNG, dlampungCBT, dlampungMJO, dlampungUNG, dmedanCBT, dmedanMJO, dmedanUNG);
var aa = 6; var ab = 6; var ac = 3;
var ba = 10; var bb = 2; var bc = 3;
var ca = 5; var cb = 4; var cc = 7;
var da = 8; var db = 8; var dc = 7;
var ea = 9; var eb = 8; var ec = 7;
model.AddConstraints
("DayaTampungColumn",
djakartaMJO + djakartaUNG + djakartaCBT == 440,
dbandungMJO + dbandungUNG + dbandungCBT == 360,
ddenpasarMJO + ddenpasarUNG + ddenpasarCBT == 320,
dlampungMJO + dlampungUNG + dlampungCBT == 160,
dmedanMJO + dmedanUNG + dmedanCBT == 400,
djakartaMJO + dbandungMJO + ddenpasarMJO + dlampungMJO + dmedanMJO <= 620,
djakartaUNG + dbandungUNG + ddenpasarUNG + dlampungUNG + dmedanUNG <= 520,
djakartaCBT + dbandungCBT + ddenpasarCBT + dlampungCBT + dmedanCBT <= 560
);
model.AddGoal
("GOALSPOINT", GoalKind.Minimize,
(
(aa + 20) * djakartaMJO + (ba + 20) * dbandungMJO + (ca + 20) * ddenpasarMJO + (da + 20) * dlampungMJO + (ea + 20) * dmedanMJO) +
(ab + 25) * djakartaUNG + (bb + 25) * dbandungUNG + (cb + 25) * ddenpasarUNG + (db + 25) * dlampungUNG + (eb + 25) * dmedanUNG +
(ac + 28) * djakartaCBT + (bc + 28) * dbandungCBT + (cc + 28) * ddenpasarCBT + (dc + 28) * dlampungCBT + (ec + 28) * dmedanCBT
);
Solution solution = context.Solve(new SimplexDirective());
Report report = solution.GetReport();
Console.Write("{0}", report);
Console.WriteLine();
Console.ReadLine();</pre>
}
now how did i parameterize it..
i want to know best minimal cost and item to allocated..
still confuse in the constrains and the goal ..
my try still stuck..
void sampleExcelMin()
{
SolverContext context = SolverContext.GetContext();
Model model = context.CreateModel();
sifusionEntities mydb = new sifusionEntities();
Set kpbs = new Set(Domain.Any, "KPBs");
Set kpws = new Set(Domain.Any, "KPWs");
Set costs1 = new Set(Domain.Any, "COSTs");
Set costs2 = new Set(Domain.Any, "COSTs");
Parameter cost = new Parameter(Domain.Real, "cost", costs1);
cost.SetBinding(mydb.COSTs, "COST1","KD_KPB");
Parameter cogm = new Parameter(Domain.Real, "cogm", costs2);
cogm.SetBinding(mydb.COSTs, "COGM","KD_KPB");
Parameter prodcapacity = new Parameter(Domain.Real, "prodcapacity", kpbs);
prodcapacity.SetBinding(mydb.KPBs, "PROD_CAPACITY", "KD_KPB");
Parameter whcapacity = new Parameter(Domain.Real, "whcapacity", kpws);
whcapacity.SetBinding(mydb.KPWs, "WH_CAPACITY", "KD_KPW");
model.AddParameters(cost, cogm, prodcapacity, whcapacity);
Decision DKPBW = new Decision(Domain.RealNonnegative, "DKPBW",kpbs);
model.AddDecision(DKPBW);
model.AddConstraint("kpbCapacity",
Model.Sum(Model.ForEach(kpbs, askpb => DKPBW[askpb] <= prodcapacity[askpb])));
model.AddConstraint("kpwLimit",
Model.ForEach(kpws, askpw => DKPBW[askpw] == whcapacity[askpw]));
model.AddGoal("goal", GoalKind.Minimize,
Model.Sum(Model.ForEach(kpbs, ww => cogm[ww] * DKPBW[ww])));
Solution solution = context.Solve();
Report report = solution.GetReport();
Console.Write("{0}", report);
Console.WriteLine(); Console.ReadLine();
}
help..