Пример #1
0
        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
        static int Main(string[] args)
        {
            int          status  = 127;
            const string DATADIR = "../..";

            try
            {
                OplFactory         oplF        = new OplFactory();
                OplErrorHandler    handler     = oplF.CreateOplErrorHandler(Console.Out);
                OplModelSource     modelSource = oplF.CreateOplModelSource(DATADIR + "/mulprod.mod");
                OplSettings        settings    = oplF.CreateOplSettings(handler);
                OplModelDefinition def         = oplF.CreateOplModelDefinition(modelSource, settings);
                Cplex         cplex            = oplF.CreateCplex();
                OplModel      opl        = oplF.CreateOplModel(def, cplex);
                OplDataSource dataSource = oplF.CreateOplDataSource(DATADIR + "/mulprod.dat");
                opl.AddDataSource(dataSource);
                opl.Generate();
                if (cplex.Solve())
                {
                    Console.Out.WriteLine();
                    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;
            }

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

            return(status);
        }
Пример #3
0
        static int Main(string[] args)
        {
            int status = 0;

            try
            {
                OplFactory      oplF    = new OplFactory();
                OplErrorHandler handler = oplF.CreateOplErrorHandler(Console.Out);
                //OplModelSource modelSource = oplF.CreateOplModelSource(DATADIR + "/Modelo3.mod");
                OplModelSource modelSource;
                OplDataSource  dataSource;
                if (args[0].Contains("1"))
                {
                    modelSource = oplF.CreateOplModelSource("C://Users//Richard Sobreiro//Desktop//PFCCodigos//Backend//VRPTW_Server//Ceplex//MultipleVehicleRoutingProblem.mod");
                    dataSource  = oplF.CreateOplDataSource("C://Users//Richard Sobreiro//Desktop//PFCCodigos//Backend//VRPTW_Server//Ceplex//MultipleVehicleRoutingProblem.dat");
                }
                else
                {
                    modelSource = oplF.CreateOplModelSource("C://Users//Richard Sobreiro//Desktop//PFCCodigos//Backend//VRPTW_Server//Ceplex//VRP.mod");
                    dataSource  = oplF.CreateOplDataSource("C://Users//Richard Sobreiro//Desktop//PFCCodigos//Backend//VRPTW_Server//Ceplex//VRP.dat");
                }
                OplSettings        settings = oplF.CreateOplSettings(handler);
                OplModelDefinition def      = oplF.CreateOplModelDefinition(modelSource, settings);
                Cplex cplex = oplF.CreateCplex();

                OplModel opl = oplF.CreateOplModel(def, cplex);
                opl.AddDataSource(dataSource);
                opl.Generate();

                if (cplex.Solve())
                {
                    Console.Out.WriteLine();
                    Console.Out.WriteLine("OBJECTIVE: " + opl.Cplex.ObjValue);
                    opl.PostProcess();
                    status = 0;
                }
                else
                {
                    Console.Out.WriteLine("No solution!");
                    status = 1;
                }
                oplF.End();
            }
            catch (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;
            }

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

            return(status);
        }
Пример #4
0
        static int Main(string[] args)
        {
            int          status  = 127;
            const string DATADIR = "../..";

            try
            {
                OplFactory         oplF        = new OplFactory();
                OplErrorHandler    handler     = oplF.CreateOplErrorHandler(Console.Out);
                OplModelSource     modelSource = oplF.CreateOplModelSource(DATADIR + "/lifegameip.mod");
                OplSettings        settings    = oplF.CreateOplSettings(handler);
                OplModelDefinition def         = oplF.CreateOplModelDefinition(modelSource, settings);
                Cplex cplex = oplF.CreateCplex();
                cplex.ReadVMConfig(DATADIR + "/process.vmc");
                OplModel opl = oplF.CreateOplModel(def, cplex);
                opl.Generate();
                cplex.Solve();
                Console.Out.WriteLine();
                Console.Out.WriteLine("OBJECTIVE: " + opl.Cplex.ObjValue);
                opl.PostProcess();
                opl.PrintSolution(Console.Out);
                if (cplex.HasVMConfig())
                {
                    Console.Out.WriteLine("cplex has a VM config");
                }
                else
                {
                    throw new IloException("cplex does not have a VM config");
                }
                cplex.DelVMConfig();

                if (cplex.HasVMConfig())
                {
                    throw new IloException("cplex still has a VM config");
                }
                else
                {
                    Console.Out.WriteLine("cplex VM config was removed");
                }

                status = 0;
                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;
            }

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

            return(status);
        }
Пример #5
0
        int Run()
        {
            int        status = 127;
            OplFactory oplF   = new OplFactory();

            if (_cl.CompileName != null)
            {
                OplCompiler    compiler    = oplF.CreateOplCompiler();
                StreamWriter   ofs         = new StreamWriter(_cl.CompileName, false);
                OplModelSource modelSource = oplF.CreateOplModelSource(_cl.ModelFileName);
                compiler.Compile(modelSource, ofs);
                ofs.Close();
                Trace("Compile");
                return(0);
            }
            if (_cl.ModelFileName == null && !_cl.IsProject)
            {
                return(0);
            }

            Trace("initial");
            OplRunConfiguration rc;
            OplErrorHandler     errHandler = oplF.CreateOplErrorHandler();

            if (_cl.IsProject)
            {
                OplProject prj = oplF.CreateOplProject(_cl.getProjectPath());
                rc = prj.MakeRunConfiguration(_cl.getRunConfigurationName());
            }
            else
            {
                if (_cl.DataFileNames.Length == 0)
                {
                    rc = oplF.CreateOplRunConfiguration(_cl.ModelFileName);
                }
                else
                {
                    rc = oplF.CreateOplRunConfiguration(_cl.ModelFileName, _cl.DataFileNames);
                }
            }
            rc.ErrorHandler = errHandler;
            OplModel    opl      = rc.OplModel;
            OplSettings settings = opl.Settings;

            settings.IsWithLocations     = true;
            settings.IsWithNames         = true;
            settings.IsForceElementUsage = _cl.IsForceElementUsage;

            status = 9;
            if (opl.ModelDefinition.hasMain())
            {
                status = opl.Main();
                Console.Out.WriteLine("main returns " + status);
                Trace("main");
            }
            else if (errHandler.Ok)
            {
                opl.Generate();
                Trace("generate model");
                if (opl.HasCplex)
                {
                    if (_cl.ExportName != null)
                    {
                        opl.Cplex.ExportModel(_cl.ExportName);
                        Trace("export model " + _cl.ExportName);
                    }
                    if (_cl.IsRelaxation)
                    {
                        Console.Out.WriteLine("RELAXATIONS to obtain a feasible problem: ");
                        opl.PrintRelaxation(Console.Out);
                        Console.Out.WriteLine("RELAXATIONS done.");
                    }
                    if (_cl.IsConflict)
                    {
                        Console.Out.WriteLine("CONFLICT in the infeasible problem: ");
                        opl.PrintConflict(Console.Out);
                        Console.Out.WriteLine("CONFLICT done.");
                    }
                    if (!_cl.IsRelaxation && !_cl.IsConflict)
                    {
                        bool result = false;
                        try
                        {
                            result = opl.Cplex.Solve();
                        }
                        catch (IloException ex)
                        {
                            Console.Out.WriteLine("### ENGINE exception: " + ex.Message);
                        }
                        if (result)
                        {
                            Trace("solve");
                            Console.Out.WriteLine();
                            Console.Out.WriteLine();
                            Console.Out.WriteLine("OBJECTIVE: " + opl.Cplex.ObjValue.ToString("F"));
                            opl.PostProcess();
                            Trace("post process");
                            if (_cl.IsVerbose)
                            {
                                opl.PrintSolution(Console.Out);
                            }
                            status = 0;
                        }
                        else
                        {
                            Trace("no solution");
                            status = 1;
                        }
                    }
                }
                else
                {//opl.hasCP()
                    bool result = false;
                    try
                    {
                        result = opl.CP.Solve();
                    }
                    catch (IloException ex)
                    {
                        Console.Out.WriteLine("### Engine exception: " + ex.Message);
                    }
                    if (result)
                    {
                        Trace("solve");
                        if (opl.CP.HasObjective())
                        {
                            Console.Out.WriteLine();
                            Console.Out.WriteLine();
                            Console.Out.WriteLine("OBJECTIVE: " + opl.CP.ObjValue.ToString("F"));
                        }
                        else
                        {
                            Console.Out.WriteLine();
                            Console.Out.WriteLine();
                            Console.Out.WriteLine("OBJECTIVE: no objective");
                        }
                        opl.PostProcess();
                        Trace("post process");
                        if (_cl.IsVerbose)
                        {
                            opl.PrintSolution(Console.Out);
                        }
                        status = 0;
                    }
                    else
                    {
                        Trace("no solution");
                        status = 1;
                    }
                }
            }
            if (_cl.ExternalDataName != null)
            {
                StreamWriter ofs = new StreamWriter(_cl.ExternalDataName, false);
                opl.PrintExternalData(ofs);
                ofs.Close();
                Trace("write external data " + _cl.ExternalDataName);
            }
            if (_cl.InternalDataName != null)
            {
                StreamWriter ofs = new StreamWriter(_cl.InternalDataName, false);
                opl.PrintInternalData(ofs);
                ofs.Close();
                Trace("write internal data " + _cl.InternalDataName);
            }

            Trace("done");
            return(status);
        }
        static void Main(string[] args)
        {
            // Assume we run in bin/Debug or bin/Release
            const string DATADIR = "../..";

            int status = 127;

            CommandLineParser parser = new CommandLineParser();

            // set some default values for the sample
            parser.modelFileName         = DATADIR + "/data/oil.mod";
            parser.configurationFileName = DATADIR + "/data/db_mssql.xml";

            parser.Parse(args);


            // set default datafilename if none specified

            if (parser.dataFileNames.Count == 0)
            {
                parser.dataFileNames.Add(DATADIR + "/data/oil.dat");
            }

            // parse the data source configuration
            CustomDataSourceConfiguration configuration = new CustomDataSourceConfiguration(parser.configurationFileName);

            // if this is the default sample, write some default data
            if (parser.CreateSampleDatabase)
            {
                CreateDefaultSampleDatabase(configuration);
            }

            try
            {
                OplFactory.DebugMode = true;
                OplFactory      oplF       = new OplFactory();
                OplErrorHandler errHandler = oplF.CreateOplErrorHandler(Console.Out);

                OplRunConfiguration rc = null;


                if (parser.dataFileNames.Count == 0)
                {
                    rc = oplF.CreateOplRunConfiguration(parser.modelFileName);
                }
                else
                {
                    rc = oplF.CreateOplRunConfiguration(parser.modelFileName,
                                                        (String[])parser.dataFileNames.ToArray(typeof(String)));
                }

                OplModel           opl = rc.GetOplModel();
                OplModelDefinition def = opl.ModelDefinition;

                OplDataSource dataSource = new SqlCustomDataSource(oplF, def, configuration);
                opl.AddDataSource(dataSource);

                opl.Generate();

                if (parser.externalDataName != null)
                {
                    using (TextWriter wt = File.CreateText(parser.externalDataName))
                        opl.PrintExternalData(wt);
                }

                bool success = opl.HasCplex ? opl.Cplex.Solve() : opl.CP.Solve();

                if (success)
                {
                    opl.PostProcess();
                    // Write results to result table
                    Console.WriteLine("Writing results");
                    SqlWriter writer = new SqlWriter(configuration, opl);
                    writer.WriteResults();
                }

                oplF.End();
                status = 0;
            }
            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);
                Console.WriteLine(ex.Message);
                status = 4;
            }

            Environment.ExitCode = status;

            Console.WriteLine("--Press <Enter> to exit--");
            Console.ReadLine();
        }
Пример #7
0
        public void RescheduleLotMachineAllocation()
        {
            // Clear scheduled lots
            foreach (Machine machine in LithographyArea.Machines)
            {
                ScheduledLotsPerMachine[machine.Name].Clear();
            }

            // Set weight of each Lot
            for (int j = 0; j < Queue.Length; j++)
            {
                Lot peekLot = Queue.PeekAt(j);

                Queue.PeekAt(j).WeightDueDate    = GetDueDateWeight(peekLot);
                Queue.PeekAt(j).WeightWIPBalance = GetWIPBalanceWeight(peekLot);
            }

            int    status           = 127;
            string solutionAsString = "";

            try
            {
                OplFactory.DebugMode = false;
                OplFactory         oplF        = new OplFactory();
                OplErrorHandler    errHandler  = oplF.CreateOplErrorHandler(Console.Out);
                OplModelSource     modelSource = oplF.CreateOplModelSource($"{Directory.GetCurrentDirectory()}/Input/LithoFinal.mod");
                OplSettings        settings    = oplF.CreateOplSettings(errHandler);
                OplModelDefinition def         = oplF.CreateOplModelDefinition(modelSource, settings);

                // Change stream to be able to read solution as a string (probably not the correct way of doing)
                StringWriter strWriter = new StringWriter();
                oplF.SetOut(strWriter);

                CP            cp         = oplF.CreateCP();
                OplModel      opl        = oplF.CreateOplModel(def, cp);
                OplDataSource dataSource = new MyCustomDataSource(oplF, Queue, LithographyArea, this);
                opl.AddDataSource(dataSource);
                opl.Generate();

                if (cp.Solve())
                {
                    Console.Out.WriteLine("OBJECTIVE: " + opl.CP.ObjValue);
                    opl.PostProcess();

                    // Get solution as string
                    solutionAsString = strWriter.ToString();

                    status = 0;
                }
                else
                {
                    Console.Out.WriteLine("No solution!");
                    status = 1;
                    this.LithographyArea.HandleDispatcherError();
                    ScheduleEndEvent(GetTime);
                    return;
                }
                oplF.End();
            }
            catch (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;
            }

            //Console.WriteLine("--Press <Enter> to exit--");
            //Console.WriteLine(status);
            //Console.ReadLine();
            //Console.WriteLine(solutionAsString);
            //Console.ReadLine();
            ChangeLotMachineAllocation(solutionAsString);
            Console.WriteLine($"Scheduled for {LithographyArea.StartDate.AddSeconds(GetTime)}");
        }
Пример #8
0
        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();
        }