コード例 #1
0
ファイル: Carseq.cs プロジェクト: andreasmattas/testcode
        static void Main(string[] args)
        {
            int status = 127;

            try
            {
                OplFactory.DebugMode = true;
                OplFactory         oplF        = new OplFactory();
                OplErrorHandler    errHandler  = oplF.CreateOplErrorHandler(Console.Out);
                OplModelSource     modelSource = oplF.CreateOplModelSourceFromString(GetModelText(), "carseq");
                OplSettings        settings    = oplF.CreateOplSettings(errHandler);
                OplModelDefinition def         = oplF.CreateOplModelDefinition(modelSource, settings);
                CP            cp         = oplF.CreateCP();
                OplModel      opl        = oplF.CreateOplModel(def, cp);
                OplDataSource dataSource = new MyData(oplF);
                opl.AddDataSource(dataSource);
                opl.Generate();

                if (cp.Solve())
                {
                    Console.Out.WriteLine("OBJECTIVE: " + opl.CP.ObjValue);
                    opl.PostProcess();
                    opl.PrintSolution(Console.Out);
                    status = 0;
                }
                else
                {
                    Console.Out.WriteLine("No solution!");
                    status = 1;
                }

                oplF.End();
            }
            catch (ILOG.OPL.OplException ex)
            {
                Console.WriteLine(ex.Message);
                status = 2;
            }
            catch (ILOG.Concert.Exception ex)
            {
                Console.WriteLine(ex.Message);
                status = 3;
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
                status = 4;
            }
            Environment.ExitCode = status;

            Console.WriteLine("--Press <Enter> to exit--");
            Console.ReadLine();
        }
コード例 #2
0
ファイル: Iterators.cs プロジェクト: andreasmattas/testcode
        static int sample3()
        {
            int status = 0;

            OplFactory.DebugMode = true;
            OplFactory oplF = new OplFactory();

            try
            {
                OplErrorHandler    errHandler = oplF.CreateOplErrorHandler(Console.Out);
                OplSettings        settings   = oplF.CreateOplSettings(errHandler);
                OplModelSource     src        = oplF.CreateOplModelSourceFromString(getModelTextSample3(), "tuple array iterator");
                OplModelDefinition def        = oplF.CreateOplModelDefinition(src, settings);
                Cplex    cplex = oplF.CreateCplex();
                OplModel opl   = oplF.CreateOplModel(def, cplex);
                opl.Generate();

                // get the string set used to index the array of tuples
                ITupleMap  arrayT = opl.GetElement("arrayT").AsTupleMap();
                ISymbolSet ids    = opl.GetElement("ids").AsSymbolSet();
                // iterate on the index set to retrieve the tuples stored in the array
                IEnumerator it = ids.GetEnumerator();
                while (it.MoveNext())
                {
                    Console.Out.Write("arrayT[" + it.Current + "] = ");
                    IMapIndexArray id = oplF.MapIndexArray(0);
                    id.Add(it.Current.ToString());
                    ITuple t = arrayT.MakeTuple();
                    arrayT.GetAt(id, t);
                    Console.Out.WriteLine(t);
                }
            }
            catch (ILOG.OPL.OplException ex)
            {
                Console.WriteLine(ex.Message);
                status = 1;
            }
            catch (IloException e)
            {
                status = 2;
                Console.Out.WriteLine("### exception: " + e.Message);
            }
            catch (System.Exception ex)
            {
                status = 3;
                Console.Out.WriteLine("### UNEXPECTED ERROR ..." + ex.Message);
            }
            oplF.End();
            return(status);
        }
コード例 #3
0
ファイル: Warehouse.cs プロジェクト: andreasmattas/testcode
        static void Main(string[] args)
        {
            int nbWarehouses = -1;
            int nbStores = -1;
            int fixedP = -1;
            int disaggregate = -1;
            for (int i = 0; i < args.Length; i++)
            {
                if ("-h".Equals(args[i]))
                {
                    usage();
                }
                else if ("fixed".Equals(args[i]))
                {
                    if (i == args.Length)
                    {
                        usage();
                    }
                    fixedP = System.Int32.Parse(args[++i]);
                }
                else if ("nbWarehouses".Equals(args[i]))
                {
                    if (i == args.Length)
                    {
                        usage();
                    }
                    nbWarehouses = System.Int32.Parse(args[++i]);
                }
                else if ("nbStores".Equals(args[i]))
                {
                    if (i == args.Length)
                    {
                        usage();
                    }
                    nbStores = System.Int32.Parse(args[++i]);
                }
                else if ("disaggregate".Equals(args[i]))
                {
                    if (i == args.Length)
                    {
                        usage();
                    }
                    disaggregate = System.Int32.Parse(args[++i]);
                }
                else
                {
                    break;
                }
            }

            if (fixedP == -1 || nbWarehouses == -1 || nbStores == -1 || disaggregate == -1)
            {
                usage();
            }

            int status = 127;
            try
            {
                OplFactory.DebugMode = true;
                OplFactory oplF = new OplFactory();
                OplErrorHandler errHandler = oplF.CreateOplErrorHandler(Console.Out);
                OplModelSource modelSource = oplF.CreateOplModelSourceFromString(GetModelText(), "warehouse");
                OplSettings settings = oplF.CreateOplSettings(errHandler);
                OplModelDefinition def = oplF.CreateOplModelDefinition(modelSource, settings);
                Cplex cplex = oplF.CreateCplex();
                OplModel opl = oplF.CreateOplModel(def, cplex);
                OplDataSource dataSource = new MyParams(oplF, nbWarehouses, nbStores, fixedP, disaggregate);
                opl.AddDataSource(dataSource);
                opl.Generate();
                if (cplex.Solve())
                {
                    Console.Out.WriteLine("OBJECTIVE: " + opl.Cplex.ObjValue);
                    opl.PostProcess();
                    opl.PrintSolution(Console.Out);
                    status = 0;
                }
                else
                {
                    Console.Out.WriteLine("No solution!");
                    status = 1;
                }

                oplF.End();
            }
            catch (ILOG.OPL.OplException ex)
            {
                Console.WriteLine(ex.Message);
                status = 2;
            }
            catch (ILOG.Concert.Exception ex)
            {
                Console.WriteLine(ex.Message);
                status = 3;
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
                status = 4;
            }

            Environment.ExitCode = status;

            Console.WriteLine("--Press <Enter> to exit--");
            Console.ReadLine();
        }
コード例 #4
0
ファイル: Carseq.cs プロジェクト: andreasmattas/testcode
        static void Main(string[] args)
        {
            int status = 127;
            try
            {
                OplFactory.DebugMode = true;
                OplFactory oplF = new OplFactory();
                OplErrorHandler errHandler = oplF.CreateOplErrorHandler(Console.Out);
                OplModelSource modelSource = oplF.CreateOplModelSourceFromString(GetModelText(), "carseq");
                OplSettings settings = oplF.CreateOplSettings(errHandler);
                OplModelDefinition def = oplF.CreateOplModelDefinition(modelSource, settings);
                CP cp = oplF.CreateCP();
                OplModel opl = oplF.CreateOplModel(def, cp);
                OplDataSource dataSource = new MyData(oplF);
                opl.AddDataSource(dataSource);
                opl.Generate();

                if (cp.Solve())
                {
                    Console.Out.WriteLine("OBJECTIVE: " + opl.CP.ObjValue);
                    opl.PostProcess();
                    opl.PrintSolution(Console.Out);
                    status = 0;
                }
                else
                {
                    Console.Out.WriteLine("No solution!");
                    status = 1;
                }

                oplF.End();
            }
            catch (ILOG.OPL.OplException ex)
            {
                Console.WriteLine(ex.Message);
                status = 2;
            }
            catch (ILOG.Concert.Exception ex)
            {
                Console.WriteLine(ex.Message);
                status = 3;
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
                status = 4;
            }
            Environment.ExitCode=status;

            Console.WriteLine("--Press <Enter> to exit--");
            Console.ReadLine();
        }
コード例 #5
0
ファイル: Warehouse.cs プロジェクト: andreasmattas/testcode
        static void Main(string[] args)
        {
            int nbWarehouses = -1;
            int nbStores     = -1;
            int fixedP       = -1;
            int disaggregate = -1;

            for (int i = 0; i < args.Length; i++)
            {
                if ("-h".Equals(args[i]))
                {
                    usage();
                }
                else if ("fixed".Equals(args[i]))
                {
                    if (i == args.Length)
                    {
                        usage();
                    }
                    fixedP = System.Int32.Parse(args[++i]);
                }
                else if ("nbWarehouses".Equals(args[i]))
                {
                    if (i == args.Length)
                    {
                        usage();
                    }
                    nbWarehouses = System.Int32.Parse(args[++i]);
                }
                else if ("nbStores".Equals(args[i]))
                {
                    if (i == args.Length)
                    {
                        usage();
                    }
                    nbStores = System.Int32.Parse(args[++i]);
                }
                else if ("disaggregate".Equals(args[i]))
                {
                    if (i == args.Length)
                    {
                        usage();
                    }
                    disaggregate = System.Int32.Parse(args[++i]);
                }
                else
                {
                    break;
                }
            }

            if (fixedP == -1 || nbWarehouses == -1 || nbStores == -1 || disaggregate == -1)
            {
                usage();
            }

            int status = 127;

            try
            {
                OplFactory.DebugMode = true;
                OplFactory         oplF        = new OplFactory();
                OplErrorHandler    errHandler  = oplF.CreateOplErrorHandler(Console.Out);
                OplModelSource     modelSource = oplF.CreateOplModelSourceFromString(GetModelText(), "warehouse");
                OplSettings        settings    = oplF.CreateOplSettings(errHandler);
                OplModelDefinition def         = oplF.CreateOplModelDefinition(modelSource, settings);
                Cplex         cplex            = oplF.CreateCplex();
                OplModel      opl        = oplF.CreateOplModel(def, cplex);
                OplDataSource dataSource = new MyParams(oplF, nbWarehouses, nbStores, fixedP, disaggregate);
                opl.AddDataSource(dataSource);
                opl.Generate();
                if (cplex.Solve())
                {
                    Console.Out.WriteLine("OBJECTIVE: " + opl.Cplex.ObjValue);
                    opl.PostProcess();
                    opl.PrintSolution(Console.Out);
                    status = 0;
                }
                else
                {
                    Console.Out.WriteLine("No solution!");
                    status = 1;
                }

                oplF.End();
            }
            catch (ILOG.OPL.OplException ex)
            {
                Console.WriteLine(ex.Message);
                status = 2;
            }
            catch (ILOG.Concert.Exception ex)
            {
                Console.WriteLine(ex.Message);
                status = 3;
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
                status = 4;
            }

            Environment.ExitCode = status;

            Console.WriteLine("--Press <Enter> to exit--");
            Console.ReadLine();
        }