Exemplo n.º 1
0
        private void Configure(IServer server, IQueue preQueue, IQueue postQueue)
        {
            m_server    = server;
            m_preQueue  = preQueue;
            m_postQueue = postQueue;

            if (m_preQueue != null)
            {
                ConnectorFactory.Connect(m_preQueue.Output, m_server.Input);
                m_entryPort = m_preQueue.Input;
            }
            else
            {
                m_entryPort = m_server.Input;
            }

            if (m_postQueue != null)
            {
                ConnectorFactory.Connect(m_server.Output, m_postQueue.Input);
                m_exitPort = m_postQueue.Output;
            }
            else
            {
                m_exitPort = m_server.Output;
            }

            // AddPort(m_entryPort);  <-- Done in port's ctor.// TODO: These ports maybe ought to be known as "Input" or "Entry", and "Output" or "Exit" instead of what they are known as.
            // AddPort(m_exitPort); <-- Done in port's ctor.

            m_server.PlaceInService();
        }
Exemplo n.º 2
0
        public void TestResourceServer()
        {
            m_noAdmitCount = 0;
            m_admitCount   = 0;

            m_model = new Model();
            ((Model)m_model).RandomServer = new Randoms.RandomServer(54321, 100);

            ItemSource factory = CreatePatientGenerator("Patient_", 25, 5.0, 3.0);
            Queue      queue   = new Queue(m_model, "TestQueue", Guid.NewGuid());

            ConnectorFactory.Connect(factory.Output, queue.Input);

            NormalDistribution dist    = new NormalDistribution(m_model, "SvcDistribution", Guid.NewGuid(), 15.0, 3.0);
            IPeriodicity       per     = new Periodicity(dist, Periodicity.Units.Minutes);
            ResourceManager    rscPool = new ResourceManager(m_model, "RscMgr", Guid.NewGuid());

            for (int i = 0; i < 3; i++)
            {
                rscPool.Add(new Resource(m_model, "rsc_" + i, Guid.NewGuid(), 1.0, 1.0, true, true, true));
            }
            ResourceServer rs = new ResourceServer(m_model, "RscSvr", Guid.NewGuid(), per, new IResourceRequest[] { new SimpleResourceRequest(1.0, rscPool) });

            rs.PlaceInService();
            ConnectorFactory.Connect(queue.Output, rs.Input);

            factory.Output.PortDataPresented += new PortDataEvent(FactoryOutput_PortDataPresented);
            queue.LevelChangedEvent          += new QueueLevelChangeEvent(Queue_LevelChangedEvent);
            rs.ServiceBeginning += new ServiceEvent(Server_ServiceBeginning);
            rs.ServiceCompleted += new ServiceEvent(Server_ServiceCompleted);

            m_model.Start();
        }
Exemplo n.º 3
0
        public void TestBufferedServer()
        {
            m_noAdmitCount = 0;
            m_admitCount   = 0;

            m_model = new Model();
            ((Model)m_model).RandomServer = new Randoms.RandomServer(54321, 100);

            ItemSource factory = CreatePatientGenerator("Patient_", 25, 5.0, 3.0);

            NormalDistribution dist    = new NormalDistribution(m_model, "SvcDistribution", Guid.NewGuid(), 15.0, 3.0);
            IPeriodicity       per     = new Periodicity(dist, Periodicity.Units.Minutes);
            IResourceManager   rscPool = new SelfManagingResource(m_model, "RscMgr", Guid.NewGuid(), 5.0, 5.0, false, true, true);

            BufferedServer bs = new BufferedServer(m_model, "RscSvr", Guid.NewGuid(), per, new IResourceRequest[] { new SimpleResourceRequest(1.0, rscPool) }, true, false);

            bs.PlaceInService();
            ConnectorFactory.Connect(factory.Output, bs.Input);

            factory.Output.PortDataPresented += new PortDataEvent(FactoryOutput_PortDataPresented);
            bs.PreQueue.LevelChangedEvent    += new QueueLevelChangeEvent(Queue_LevelChangedEvent);
            bs.ServiceBeginning += new ServiceEvent(Server_ServiceBeginning);
            bs.ServiceCompleted += new ServiceEvent(Server_ServiceCompleted);

            m_model.Start();
        }
Exemplo n.º 4
0
        private PortManagementFacade Setup(out IInputPort in0, out IInputPort in1, out IOutputPort out0, out IOutputPort out1, out InputPortManager facadeIn0, out InputPortManager facadeIn1, out OutputPortManager facadeOut0, out OutputPortManager facadeOut1, out SimpleOutputPort entryPoint0, out SimpleOutputPort entryPoint1)
        {
            ManagementFacadeBlock mfb = new ManagementFacadeBlock();

            out0 = new SimpleOutputPort(null, "Out0", Guid.NewGuid(), mfb, null, null);
            out1 = new SimpleOutputPort(null, "Out1", Guid.NewGuid(), mfb, null, null);
            in0  = new SimpleInputPort(null, "In0", Guid.NewGuid(), mfb, null);
            in1  = new SimpleInputPort(null, "In1", Guid.NewGuid(), mfb, null);

            int i0 = 0;

            entryPoint0 = new SimpleOutputPort(null, "", Guid.NewGuid(), null, delegate(IOutputPort iop, object selector) { return(string.Format("Src0 ({0})", i0++)); }, null);
            ConnectorFactory.Connect(entryPoint0, in0);

            int i1 = 0;

            entryPoint1 = new SimpleOutputPort(null, "", Guid.NewGuid(), null, delegate(IOutputPort iop, object selector) { return(string.Format("Src1 ({0})", i1++)); }, null);
            ConnectorFactory.Connect(entryPoint1, in1);

            out0.PortDataPresented += new PortDataEvent(delegate(object data, IPort where) { Console.WriteLine(string.Format("{0} presented at {1}.", data.ToString(), where.Name)); });
            out1.PortDataPresented += new PortDataEvent(delegate(object data, IPort where) { Console.WriteLine(string.Format("{0} presented at {1}.", data.ToString(), where.Name)); });

            PortManagementFacade pmf = new PortManagementFacade(mfb);

            facadeIn0  = pmf.ManagerFor(in0);
            facadeIn1  = pmf.ManagerFor(in1);
            facadeOut0 = pmf.ManagerFor(out0);
            facadeOut1 = pmf.ManagerFor(out1);

            return(pmf);
        }
Exemplo n.º 5
0
        public void TestResourceServerComplexDemands()
        {
            m_noAdmitCount = 0;
            m_admitCount   = 0;

            m_model = new Model();
            ((Model)m_model).RandomServer = new Randoms.RandomServer(54321, 100);

            ItemSource factory = CreatePatientGenerator("Patient_", 50, 5.0, 3.0);
            Queue      queue   = new Queue(m_model, "TestQueue", Guid.NewGuid());

            ConnectorFactory.Connect(factory.Output, queue.Input);

            NormalDistribution   dist    = new NormalDistribution(m_model, "SvcDistribution", Guid.NewGuid(), 240.0, 45.0);
            IPeriodicity         per     = new Periodicity(dist, Periodicity.Units.Minutes);
            SelfManagingResource nursing = new SelfManagingResource(m_model, "Nursing", Guid.NewGuid(), 7.0, 7.0, false, false, true);
            SelfManagingResource clerks  = new SelfManagingResource(m_model, "Clerks", Guid.NewGuid(), 6.0, 6.0, false, false, true);
            SelfManagingResource doctors = new SelfManagingResource(m_model, "Doctors", Guid.NewGuid(), 2.0, 2.0, false, false, true);

            MultiResourceTracker mrt = new MultiResourceTracker(m_model);

            mrt.Filter = ResourceEventRecordFilters.AcquireAndReleaseOnly;
            //mrt.Filter = ResourceTracker.Filters.AllEvents;
            mrt.AddTargets(nursing, clerks, doctors);

            IResourceRequest[] demands = new IResourceRequest[] {
                new SimpleResourceRequest(.20, nursing),
                new SimpleResourceRequest(.15, clerks),
                new SimpleResourceRequest(.05, doctors)
            };

            ResourceServer rs = new ResourceServer(m_model, "RscSvr", Guid.NewGuid(), per, demands);

            rs.PlaceInService();
            ConnectorFactory.Connect(queue.Output, rs.Input);

            factory.Output.PortDataPresented += new PortDataEvent(FactoryOutput_PortDataPresented);
            queue.LevelChangedEvent          += new QueueLevelChangeEvent(Queue_LevelChangedEvent);
            rs.ServiceBeginning += new ServiceEvent(Server_ServiceBeginning);
            rs.ServiceCompleted += new ServiceEvent(Server_ServiceCompleted);

            m_model.Start();

//          string dataFileName = Highpoint.Sage.Utility.DirectoryOperations.GetAppDataDir() + @"Data.csv";
//			System.IO.TextWriter tw = new System.IO.StreamWriter(dataFileName);
//			foreach ( ResourceEventRecord rer in mrt ) {
//				tw.WriteLine(rer.When.ToLongTimeString()+","
//					+rer.Resource.Name+","
//					+rer.Action.ToString()+","
//					+rer.Available	);
//			}
//			tw.Close();
//			System.Diagnostics.Process.Start("excel.exe","\""+dataFileName+"\"");

            Console.WriteLine(new CSVDumper(mrt, new CompoundComparer(ResourceEventRecord.ByAction(false), ResourceEventRecord.ByTime(false))).ToString());
        }
Exemplo n.º 6
0
        public MultiQueueHead(IModel model, string name, Guid guid, ArrayList queues, ISelectionStrategy selStrategy)          // TODO: Want to add/remove queues eventually, and use an IQueueSelectionStrategy.
        {
            m_selStrategy          = selStrategy;
            selStrategy.Candidates = queues;

            m_input = new SimpleInputPort(model, name, guid, this, new DataArrivalHandler(OnDataPushIn));

            Outputs = new IOutputPort[queues.Count];
            for (int i = 0; i < Outputs.GetLength(0); i++)
            {
                string portName = name + "#" + i;
                Outputs[i] = new SimpleOutputPort(model, portName, Guid.NewGuid(), this, new DataProvisionHandler(OnDataPullOut), null);
                ConnectorFactory.Connect(Outputs[i], ((Queue)queues[i]).Input);
            }
        }
Exemplo n.º 7
0
        public void TestSimplePortNetwork()
        {
            for (int i = 0; i < m_nBlocks; i++)
            {
                m_blocks[i] = new SimplePassThroughPortOwner(m_model, "Block" + i, Guid.NewGuid());
                if (i > 0)
                {
                    ConnectorFactory.Connect(m_blocks[i - 1].Out, m_blocks[i].In);
                }
            }

            m_blocks[0].In.Put("Random string");
            Debug.WriteLine(m_blocks[m_nBlocks - 1].Out.Peek(null));


            Debug.WriteLine(m_blocks[m_nBlocks - 1].Out.Take(null));
        }
Exemplo n.º 8
0
        public void TestServerBasics()
        {
            m_noAdmitCount = 0;
            m_admitCount   = 0;

            m_model = new Model();
            ((Model)m_model).RandomServer = new Randoms.RandomServer(54321, 100);

            ItemSource patientFactory  = CreatePatientGenerator("Patient_", 500, 5.0, 3.0);
            IServer    receiving       = CreateProcessStep("Receiving", 3.0, 5.0, 8.0);
            ISplitter  evaluation      = CreateBranch("Evaluation", 0.20);
            IServer    admit           = CreateProcessStep("Admit", 3.0, 5.0, 9.0);
            IServer    inPatientTreat  = CreateProcessStep("InPatientTreat", 300.0, 2160.0, 7200.0);
            IServer    discharge       = CreateProcessStep("Discharge", 3.0, 5.0, 8.0);
            IServer    outPatientTreat = CreateProcessStep("OutPatientTreat", 300.0, 2160.0, 7200.0);
            IJoiner    toStreet        = new PushJoiner(m_model, "Push Joiner", Guid.NewGuid(), 2);
            ItemSink   street          = new ItemSink(m_model, "Street", Guid.NewGuid());


            ConnectorFactory.Connect(patientFactory.Output, receiving.Input);
            ConnectorFactory.Connect(receiving.Output, evaluation.Input);
            ConnectorFactory.Connect(evaluation.Outputs[0], admit.Input);
            ConnectorFactory.Connect(admit.Output, inPatientTreat.Input);
            ConnectorFactory.Connect(inPatientTreat.Output, discharge.Input);
            ConnectorFactory.Connect(discharge.Output, toStreet.Inputs[0]);
            ConnectorFactory.Connect(evaluation.Outputs[1], outPatientTreat.Input);
            ConnectorFactory.Connect(outPatientTreat.Output, toStreet.Inputs[1]);
            ConnectorFactory.Connect(toStreet.Output, street.Input);


            evaluation.Outputs[0].PortDataPresented += new PortDataEvent(Admit_Patient);           // Count admitted.
            evaluation.Outputs[1].PortDataPresented += new PortDataEvent(NoAdmit_Patient);         // Count not-admitted.

            inPatientTreat.ServiceBeginning += new ServiceEvent(Server_ServiceBeginning);
            inPatientTreat.ServiceCompleted += new ServiceEvent(Server_ServiceCompleted);

            outPatientTreat.ServiceBeginning += new ServiceEvent(Server_ServiceBeginning);
            outPatientTreat.ServiceCompleted += new ServiceEvent(Server_ServiceCompleted);

            m_model.Start();

            Console.WriteLine("NoAdmit = " + m_noAdmitCount + ", and admitted = " + m_admitCount);
        }
Exemplo n.º 9
0
        public void TestOneInOneOutPushPullTransform()
        {
            DLog dlog = new DLog(null, null, null, Guid.NewGuid());

            double i1 = 0.1;

            entryPoint1 = new SimpleOutputPort(null, "", Guid.NewGuid(), null, delegate(IOutputPort iop, object selector) { return(i1++); }, null);
            ConnectorFactory.Connect(entryPoint1, dlog.Ports.Inputs[0]);

            dlog.Ports.Outputs[0].PortDataPresented += new PortDataEvent(delegate(object data, IPort where) { Console.WriteLine(string.Format("{0} presented at {1}.", data.ToString(), where.Name)); });


            Console.WriteLine(String.Format("Pushing {0}", i1)); entryPoint1.OwnerPut(i1++);
            Console.WriteLine(String.Format("Pushing {0}", i1)); entryPoint1.OwnerPut(i1++);


            Console.WriteLine(dlog.Ports.Outputs[0].Take(null));
            Console.WriteLine(dlog.Ports.Outputs[0].Take(null));
            Console.WriteLine(dlog.Ports.Outputs[0].Take(null));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Connects the Nexus to the specified port If the specified port is an input port, creates an output port
        /// on the nexus and adds a connector to the specified port from that output port. The relationship does not
        /// allow taking or peeking from the nexus.
        /// </summary>
        /// <param name="port">The port.</param>
        public void Bind(IPort port)
        {
            IPort myNewPort = null;

            if (port is IInputPort)
            {
                myNewPort = new SimpleOutputPort(m_model, "Output" + (m_outCount++), Guid.NewGuid(), this, m_cantTakeOrPeekFromNexus, m_cantTakeOrPeekFromNexus);
            }
            else if (port is IOutputPort)
            {
                myNewPort = new SimpleInputPort(m_model, "Input" + (m_inCount++), Guid.NewGuid(), this, m_canAlwaysAcceptData);
                myNewPort.PortDataAccepted += new PortDataEvent(OnPortDataAccepted);
            }
            else
            {
                throw new ApplicationException("Unknown port type " + port.GetType().Name + " encountered.");
            }
            // m_ports.AddPort(myNewPort); <-- Done in port's ctor.
            ConnectorFactory.Connect(port, myNewPort);
        }
Exemplo n.º 11
0
        public void TestQueueBasics()
        {
            m_model = new Model();
            m_model.RandomServer = new Randoms.RandomServer(54321, 100);

            ItemSource itemFactory = CreateItemGenerator("Item_", 500, 5.0, 3.0);
            IQueue     q1          = new Queue(m_model, "Queue1", Guid.NewGuid(), 10);
            IQueue     q2          = new Queue(m_model, "Queue2", Guid.NewGuid(), 10);
            IQueue     q3          = new Queue(m_model, "Queue3", Guid.NewGuid(), 10);

            ConnectorFactory.Connect(itemFactory.Output, q1.Input);
            ConnectorFactory.Connect(q1.Output, q2.Input);
            ConnectorFactory.Connect(q2.Output, q3.Input);

            itemFactory.Output.PortDataPresented += new PortDataEvent(Output_PortDataPresented);

            q1.LevelChangedEvent += new QueueLevelChangeEvent(Queue_LevelChangedEvent);
            q2.LevelChangedEvent += new QueueLevelChangeEvent(Queue_LevelChangedEvent);
            q3.LevelChangedEvent += new QueueLevelChangeEvent(Queue_LevelChangedEvent);

            q3.Output.PortDataPresented += new PortDataEvent(Output_PortDataPresented);

            m_model.Start();
        }