public BlendResultModel Coz(BlendDataModel data) { _data = data; ResultModel = _blendOptimization.Solve(_data); return(ResultModel); }
public ActionResult ModelCoz() { var data1 = new BlendDataModel() { A = 5, NbElements = 3, NbRaw = 2, NbScrap = 2, NbIngot = 1, Alloy = 71.0, Cm = new double[] { 22.0, 10.0, 13.0 }, Cr = new double[] { 6.0, 5.0 }, Cs = new double[] { 7.0, 8.0 }, Ci = new double[] { 9.0 }, _p = new double[] { 0.05, 0.30, 0.60 }, _P = new double[] { 0.10, 0.40, 0.80 }, PRaw = new double[][] { new double[] { 0.20, 0.01 }, new double[] { 0.05, 0.00 }, new double[] { 0.05, 0.30 } }, PScrap = new double[][] { new double[] { 0.00, 0.01 }, new double[] { 0.60, 0.00 }, new double[] { 0.40, 0.70 } }, PIngot = new double[][] { new double[] { 0.10 }, new double[] { 0.45 }, new double[] { 0.45 } } }; //TempData["result"] = _blendOptimization.ResultMessage; //var model = new BlendResultViewModel() //{ // blendResultModel = new BlendResultModel() // { // Satatus = _blendOptimization.ResultModel.Satatus, // ObjectiveValue = _blendOptimization.ResultModel.ObjectiveValue, // ResultMessage = _blendOptimization.ResultModel.ResultMessage, // EVals = _blendOptimization.ResultModel.EVals, // IVals = _blendOptimization.ResultModel.IVals, // MVals = _blendOptimization.ResultModel.MVals, // RVals = _blendOptimization.ResultModel.RVals, // SVals = _blendOptimization.ResultModel.SVals // } //}; var model = new BlendResultViewModel() { blendResultModel = _blendOptimization.Coz(data1) }; return(View(model)); }
/// <summary> /// Blend Optimizasyon Çözüm Modeli /// </summary> /// <param name="data"></param> /// <returns>BlendResultModel</returns> private BlendResultModel Model(BlendDataModel data) { #region Veriler //parametrelerin local değişkenlere aktarılması. _modelAdi = "Blend"; _dataModel = data; cplex = new Cplex(); #endregion #region Karar Değişkenleri //Karar Değişkenleri m = cplex.NumVarArray(_dataModel.NbElements, 0.0, Double.MaxValue); r = cplex.NumVarArray(_dataModel.NbRaw, 0.0, Double.MaxValue); s = cplex.NumVarArray(_dataModel.NbScrap, 0.0, Double.MaxValue); i = cplex.NumVarArray(_dataModel.NbIngot, 0.0, Double.MaxValue); le = new INumVar[_dataModel.NbElements]; #endregion #region Amaç Fonksiyonu // Objective Function: Minimize Cost cplex.AddMinimize(cplex.Sum(cplex.ScalProd(_dataModel.Cm, m), cplex.ScalProd(_dataModel.Cr, r), cplex.ScalProd(_dataModel.Cs, s), cplex.ScalProd(_dataModel.Ci, i))); #endregion #region Kısıtlar // Min and max quantity of each element in alloy for (int j = 0; j < _dataModel.NbElements; j++) { le[j] = cplex.NumVar(_dataModel._p[j] * _dataModel.Alloy, _dataModel._P[j] * _dataModel.Alloy); } // Constraint: produce requested quantity of alloy cplex.AddEq(cplex.Sum(le), _dataModel.Alloy); // Constraints: Satisfy element quantity requirements for alloy for (int j = 0; j < _dataModel.NbElements; j++) { cplex.AddEq(le[j], cplex.Sum(m[j], cplex.ScalProd(_dataModel.PRaw[j], r), cplex.ScalProd(_dataModel.PScrap[j], s), cplex.ScalProd(_dataModel.PIngot[j], i))); } #endregion #region Çözümün işlenmesi try { if (cplex.Solve()) { if (cplex.GetStatus().Equals(Cplex.Status.Infeasible)) { throw new ILOG.Concert.Exception("No feasible solution found!"); } #region Sonuçların Alınması Results = new BlendResultModel() { Satatus = cplex.GetStatus().ToString(), ObjectiveValue = cplex.GetObjValue(), ResultMessage = "Çözüm başarılı.", BlendResults = new BlendResult() { MVals = cplex.GetValues(m), RVals = cplex.GetValues(r), SVals = cplex.GetValues(s), IVals = cplex.GetValues(i), EVals = cplex.GetValues(le) } }; #endregion } cplex.End(); return(Results); } catch (ILOG.Concert.Exception exc) { //exc.GetBaseException(); Console.WriteLine("Concert exception '" + exc + "' caught"); Console.ReadKey(); } return(Results); #endregion }
public BlendResultModel Solve(BlendDataModel data) { Model(data); return(Results); }