public BlendResultModel Coz(BlendDataModel data) { _data = data; ResultModel = _blendOptimization.Solve(_data); return(ResultModel); }
/// <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 }