static void Main(string[] args)
        {
            int          status  = 127;
            const string DATADIR = "../..";

            try
            {
                OplFactory.DebugMode = true;
                OplFactory         oplF        = new OplFactory();
                OplErrorHandler    errHandler  = oplF.CreateOplErrorHandler(Console.Out);
                OplModelSource     modelSource = oplF.CreateOplModelSource(DATADIR + "/customDataSource.mod");
                OplSettings        settings    = oplF.CreateOplSettings(errHandler);
                OplModelDefinition def         = oplF.CreateOplModelDefinition(modelSource, settings);
                Cplex         cplex            = oplF.CreateCplex();
                OplModel      opl        = oplF.CreateOplModel(def, cplex);
                OplDataSource dataSource = new MyCustomDataSource(oplF);
                opl.AddDataSource(dataSource);
                opl.Generate();
                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.Message);
                status = 4;
            }

            Environment.ExitCode = status;

            Console.WriteLine("--Press <Enter> to exit--");
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            int status = 127;
            const string DATADIR = "../..";
            try
            {
                OplFactory.DebugMode = true;
                OplFactory oplF = new OplFactory();
                OplErrorHandler errHandler = oplF.CreateOplErrorHandler(Console.Out);
                OplModelSource modelSource = oplF.CreateOplModelSource(DATADIR + "/customDataSource.mod");
                OplSettings settings = oplF.CreateOplSettings(errHandler);
                OplModelDefinition def = oplF.CreateOplModelDefinition(modelSource, settings);
                Cplex cplex = oplF.CreateCplex();
                OplModel opl = oplF.CreateOplModel(def, cplex);
                OplDataSource dataSource = new MyCustomDataSource(oplF);
                opl.AddDataSource(dataSource);
                opl.Generate();
                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.Message);
                status = 4;
            }

            Environment.ExitCode = status;

            Console.WriteLine("--Press <Enter> to exit--");
            Console.ReadLine();
        }
    public MyEventCachingBridge(MyCustomDataSource source, int eventRelayInterval)
    {
        _disposables = new CompositeDisposable();
        mSource      = source;
        // Magical Reactive Extensions code goes here that subscribes to all 3 events...
        //
        //   mSource.AddingThing
        //   mSource.ChangingThing
        //   mSource.RemovingThing
        //
        //  ...filters and records a list of the events as they are received ( maintaining order of events too ),
        //  then every eventRelayInterval milliseconds, plays back the events in bulk to update the GUI
        //  ( on the GUIs thread ).  Note that LINQ will be used to filter the Things so that a subset of
        //  Thing changes are relayed to the GUI - i.e. - not all Thing events are observed by the GUI.
        _adds = Observable.FromEvent <EventDelegateAdd, Thing>(
            ev => new EventDelegateAdd(ev),
            h => mSource.AddingThing += h,
            h => mSource.AddingThing -= h);
        _changes = Observable.FromEvent <EventDelegateChange, Thing>(
            ev => new EventDelegateChange(ev),
            h => mSource.ChangingThing += h,
            h => mSource.ChangingThing -= h);
        _removes = Observable.FromEvent <EventDelegateRemove, Thing>(
            ev => new EventDelegateRemove(ev),
            h => mSource.RemovingThing += h,
            h => mSource.RemovingThing -= h);

        _buffer = Observable.Merge(
            _adds.Select(e => Tuple.Create(e, ThingEventType.Add)),
            _changes.Select(e => Tuple.Create(e, ThingEventType.Change)),
            _removes.Select(e => Tuple.Create(e, ThingEventType.Remove)))
                  .Buffer(TimeSpan.FromMilliseconds(eventRelayInterval));

        _replayer = new ReplaySubject <IList <Tuple <Thing, ThingEventType> > >();
        _disposables.Add(_buffer.Subscribe(_replayer));
    }
示例#4
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)}");
        }