Пример #1
0
 public WorkplaceControl(Workplace workplace)
 {
     Workplace           = workplace;
     Workplace.Updated  += new EventHandler((a, b) => { this.Invoke(new MethodInvoker(() => { this.Rebind(); })); });
     Workplace.Finished += new EventHandler((a, b) => { this.Invoke(new MethodInvoker(() => { this.Rebind(); })); });
     InitializeComponent();
     this.DoubleBuffered = true;
     Rebind();
     workplaceName.DataBindings.Add("Text", Workplace, "Identification");
     productLabel.DataBindings.Add("Text", Workplace, "Contents");
 }
Пример #2
0
        public void StartWorkplaceThread(Workplace workplace)
        {
            if (workplaceThreads == null)
            {
                workplaceThreads = new Dictionary <Workplace, WorkplaceThread>();
            }
            if (!workplaceThreads.ContainsKey(workplace))
            {
                workplaceThreads.Add(workplace, new WorkplaceThread(workplace));
            }

            workplaceThreads[workplace].Run();
        }
Пример #3
0
 public WorkplaceThread(Workplace workplace)
 {
     _workplace = workplace;
 }
Пример #4
0
        // TRUE: queue je neprazdna.
        // FALSE: queue je prazdna.
        public bool Dispatch()
        {
            Swapspace sws = FindSwapspaceAtPosition(CarrierPositionP);

            // 1) Je neco ve voziku?
            if (!CarrierContents.Empty)
            {
                // 1A) Je produkt ve voziku hotovy?
                if (CarrierContents.Product.IsFinished)
                {
                    EndPoint ep = FindEndPointAtPosition(CarrierPositionP);
                    // Vyloz ho nebo odvez na nejblizsi odkladiste.
                    if (ep == null || !ep.Contents.Empty)
                    {
                        // TODO: Do nejblizsiho prazdneho odkladiste, ne prvniho v poradi.
                        foreach (EndPoint e in EndPoints)
                        {
                            if (e.Contents.Empty)
                            {
                                PathFind(e.Location);
                                Log("Vezu to ke konci.");
                                return(true);
                            }
                        }
                        Log("Vsechny konce jsou plne. Budu delat neco jineho.");
                        //return false;
                    }
                    else
                    {
                        // Vyloz.
                        ep.Contents     = CarrierContents;
                        CarrierContents = new ProductHeap(null, 0);
                        Log("Vykladam na konci.");
                        return(Dispatch());
                    }
                }
                else
                {
                    Workplace wp = Workplaces[CarrierContents.Product.Product.Actions[CarrierContents.Product.Job].Place];
                    // Odvez produkt ve voziku na dalsi stanoviste.
                    if (wp.Contents.Empty)
                    {
                        if (CarrierPositionP.Equals(wp.Location))
                        {
                            // Vyloz.
                            wp.Contents     = CarrierContents;
                            CarrierContents = new ProductHeap(null, 0);
                            Log(String.Format("Vykladam na dalsim stanovisti ({0}).", wp.Identification));
                            return(Dispatch());
                        }
                        else
                        {
                            PathFind(wp.Location);
                            Log(String.Format("Jdu na dalsi stanoviste ({0}).", wp.Identification));
                            return(true);
                        }
                    }
                    else
                    {
                        // Protoze je dalsi plny, musim to zavest na odkladiste

                        // TODO: Nejblizsi.
                        Swapspace swapspace = FindSwapspaceAtPosition(CarrierPositionP);
                        if (swapspace == null)
                        {
                            foreach (Swapspace s in Swapspaces)
                            {
                                if (s.Contents.Empty)
                                {
                                    PathFind(s.Location);
                                    return(true);
                                }
                            }
                            Log(String.Format("Castecny deadlock (stanoviste {0} je plne, ale neni swapspace).", wp.Identification));
                        }
                        else
                        {
                            swapspace.Contents = CarrierContents;
                            CarrierContents    = new ProductHeap(null, 0);
                            Log("Vykladam na swapspacu.");
                            return(Dispatch());
                        }
                    }
                }
            }
            else
            {
                if (sws != null && !sws.Contents.Empty && CanDirectlyDealWith(sws.Contents))
                {
                    CarrierContents = sws.Contents;
                    sws.Contents    = new ProductHeap(null, 0);
                    Log("Vzal jsem si neco ze swapspace.");
                    return(Dispatch());
                }
                // 2) Je neco na startu?
                if (!StartIsEmpty)
                {
                    // Jdi na start a seber to.
                    if (CanDealWith(StartContents))
                    {
                        if (CarrierPositionP.Equals(StartLocation))
                        {
                            CarrierContents = StartContents;
                            StartContents   = new ProductHeap(null, 0);
                            Log("Sbiram polotovar ze startu.");
                            return(Dispatch());
                        }
                        else
                        {
                            PathFind(StartLocation);
                            Log("Jdu na start sebrat polotovar.");
                            return(true);
                        }
                    }
                }

                {
                    List <Workplace> tenders = new List <Workplace>();
                    foreach (Workplace wp in Workplaces)
                    {
                        if (!wp.Contents.Empty && wp.State == WorkplaceState.NoJob && CanDealWith(wp.Contents))
                        {
                            // Naviguj tam.
                            if (wp.Location.Equals(CarrierPositionP))
                            {
                                // Seber to.
                                CarrierContents = wp.Contents;
                                wp.Contents     = new ProductHeap(null, 0);
                                Log("Sbiram produkt ze stanoviste.");
                                return(Dispatch());
                            }
                            tenders.Add(wp);
                        }
                    }
                    // TODO: nejblizsi, ne prvni.
                    if (tenders.Count > 0)
                    {
                        PathFind(tenders[0].Location);
                        Log("Jedu si na stanoviste pro produkt.");
                        return(true);
                    }
                    else
                    {
                        Log("Jel bych pro produkt, ale nemel bych kam s nim.");
                    }
                }
            }

            // Neni "normalni prace". Vezmi prvni vec z odkladist.
            if (CarrierContents.Empty && (sws == null || sws.Contents.Empty))
            {
                foreach (Swapspace sw in Swapspaces)
                {
                    if (!sw.Contents.Empty && CanDealWith(sw.Contents))
                    {
                        PathFind(sw.Location);
                        Log("Jedu si do swapspace pro produkt. Dalsi misto je prazdne, nevznikne deadlock.");
                        return(true);
                    }
                }
            }

            // TODO: Neni vubec prace, vypadni od vsech klicovych bodu.
            if (FindPathNodeID(CarrierPositionP) != int.MaxValue && IsImportantPoint(PathNodes[FindPathNodeID(CarrierPositionP)]))
            {
                Log("Neni prace. Odstupuji od dulezitych bodu.");
                PathNode nearestUnimportant = FindNearestUnimportant(CarrierPositionP);
                if (nearestUnimportant != null)
                {
                    PathFind(nearestUnimportant.Location);
                    return(true);
                }
            }

            Log("Není žádná vykonatelná práce.");
            return(false);
        }