コード例 #1
0
ファイル: Program.cs プロジェクト: OpResCodes/SPP
        private static Graph GenerateGraph(string gdxFile, string v, string w)
        {
            if (!File.Exists(gdxFile))
            {
                throw new ArgumentException("Specified gdx file not found.");
            }
            //Workspace
            FileInfo f = new FileInfo(gdxFile);

            GAMS.GAMSWorkspace gamsProject = new GAMS.GAMSWorkspace(f.Directory.FullName);

            using (GAMS.GAMSDatabase db = gamsProject.AddDatabaseFromGDX(gdxFile))
            {
                //read nodes
                Dictionary <string, GamsNode> nodeLookup = new Dictionary <string, GamsNode>();
                GAMS.GAMSSet gdxNodeSet = db.GetSet(v);
                foreach (GAMS.GAMSSetRecord record in gdxNodeSet)
                {
                    nodeLookup.Add(record.Keys[0], new GamsNode(record.Keys[0]));
                }
                //read arcs
                GAMS.GAMSParameter gdxWeightPar = db.GetParameter(w);
                Arc[] arcs = new Arc[gdxWeightPar.NumberRecords];
                int   k    = 0;
                foreach (GAMS.GAMSParameterRecord record in gdxWeightPar)
                {
                    string first  = record.Keys[0];
                    string second = record.Keys[1];
                    arcs[k] = new Arc(nodeLookup[first], nodeLookup[second], record.Value == double.Epsilon ? 0 : record.Value);
                    k++;
                }
                return(new Graph(arcs, nodeLookup.Values.ToArray()));
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: OpResCodes/SPP
        private static void ReturnResultGdx(string gdxFile, ShortestPath[] paths, long compTime)
        {
            FileInfo f = new FileInfo(gdxFile);

            GAMS.GAMSWorkspace gamsProject = new GAMS.GAMSWorkspace(f.Directory.FullName);
            using (GAMS.GAMSDatabase db = gamsProject.AddDatabaseFromGDX(gdxFile))
            {
                GAMS.GAMSParameter resultParameter;
                try
                {
                    resultParameter = db.GetParameter("spp");
                    resultParameter.Clear();
                }
                catch
                {
                    resultParameter = db.AddParameter("spp", 2);
                }

                for (int i = 0; i < paths.Length; i++)
                {
                    if (!paths[i].IsEmpty)
                    {
                        resultParameter.AddRecord(
                            ((GamsNode)paths[i].OriginNode).GamsSetElement,
                            ((GamsNode)paths[i].DestinationNode).GamsSetElement).Value = paths[i].TotalWeight;
                    }
                }

                //add computation time
                GAMS.GAMSParameter statPar;
                try
                {
                    statPar = db.GetParameter("spp_stats");
                    statPar.Clear();
                }
                catch
                {
                    statPar = db.AddParameter("spp_stats", 1);
                }
                statPar.AddRecord("Time_seconds").Value = Convert.ToDouble(compTime) / 1000d;
                db.Export(f.FullName);
            }
        }