Ejemplo n.º 1
0
        private void GetDual()
        {
            SchemeDualValue = _grbModelMaster.GetConstrByName("ct1").Pi;
            FADualValue     = _grbModelMaster.GetConstrByName("ct2").Pi;

            DualSolution.Clear();
            foreach (Node n in Data.NodeSet)
            {
                GRBConstr constr    = _grbModelMaster.GetConstrByName("ct3_" + n.ID);
                double    dualValue = constr.Pi;
                DualSolution.Add(n, dualValue);
            }
        }
        bool SolveMaster()
        {
            _grbModel.Optimize();
            int status   = _grbModel.Get(GRB.IntAttr.Status);
            int solution = _grbModel.Get(GRB.IntAttr.SolCount);

            if (status == GRB.Status.OPTIMAL || (status == GRB.Status.TIME_LIMIT && solution > 0))
            {
                foreach (Node n in Data.NodeSet)
                {
                    GRBConstr constr = _grbModel.GetConstrByName("ct1_" + n.ID);
                    Dual[n] = constr.Get(GRB.DoubleAttr.Pi);
                    n.ParseSolution(2);
                    n.ParseSolution(1);
                }
                foreach (Arc a in Data.ArcSet)
                {
                    a.ParseSolution();
                }

                double k0 = _grbModel.GetVarByName("k_0").Get(GRB.DoubleAttr.X);
                double k1 = _grbModel.GetVarByName("k_1").Get(GRB.DoubleAttr.X);

                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
 private void Output()
 {
     Console.WriteLine("---g---");
     foreach (Node n in Frmk.Data.NodeSet)
     {
         double g = _model.GetConstrByName("ct_g_" + n.ID).Pi;
         Console.WriteLine("g_{0}={1}", n.ID, g.ToString());
     }
     Console.WriteLine("---f---");
     foreach (Arc a in Frmk.Data.ArcSet)
     {
         double fPlus  = _model.GetConstrByName("ct_f+_" + a.FromNode.ID + "_" + a.ToNode.ID).Pi;
         double fMinus = _model.GetConstrByName("ct_f-_" + a.FromNode.ID + "_" + a.ToNode.ID).Pi;
         Console.WriteLine("f+_{0}_{1}={2}", a.FromNode.ID, a.ToNode.ID, fPlus.ToString());
         Console.WriteLine("f-_{0}_{1}={2}", a.FromNode.ID, a.ToNode.ID, fMinus.ToString());
     }
 }
Ejemplo n.º 4
0
        private void ChangeNBreaksGurobi(GRBModel pModel, GRBLinExpr pTotalStepsConst, GRBVar[] pDecVar, int intNClasses, int intNFeatures)
        {
            try
            {
                Cs    = new double[intNClasses + 1];
                cbIdx = new int[intNClasses + 1];                         // For Graph
                int intNDecVar = (intNFeatures * (intNFeatures + 1)) / 2; // Add L0_0

                pModel.Remove(pModel.GetConstrByName("Nsteps"));
                pModel.AddConstr(pTotalStepsConst, GRB.EQUAL, intNClasses, "Nsteps");

                //Solving
                pModel.Optimize();

                //Add Results to CS array
                Cs[0] = arrEst[0]; //Estimate Array was sorted
                int intIdxCs = 0;


                if (pModel.Get(GRB.IntAttr.Status) == GRB.Status.OPTIMAL)
                {
                    for (int i = 0; i < intNDecVar; i++)
                    {
                        if (pDecVar[i].Get(GRB.DoubleAttr.X) == 1)
                        {
                            intIdxCs++;
                            string strName      = pDecVar[i].Get(GRB.StringAttr.VarName);
                            int    intIndexUBar = strName.IndexOf("_");
                            string strTo        = strName.Substring(intIndexUBar + 1);
                            int    intToValue   = Convert.ToInt16(strTo);
                            Cs[intIdxCs]    = arrEst[intToValue - 1]; //Closed
                            cbIdx[intIdxCs] = intToValue - 1;
                        }
                    }
                }

                txtObjValue.Text = pModel.Get(GRB.DoubleAttr.ObjVal).ToString("N5");
            }
            catch (Exception ex)
            {
                MessageBox.Show(this.Handle.ToString() + " Error:" + ex.Message);
                return;
            }
        }