예제 #1
0
파일: Model.cs 프로젝트: agentydragon/IVU
 public Workplace(int identification, Point location, SynchronizationContext context)
 {
     this.context   = context;
     Identification = identification;
     Location       = location;
     contents       = new ProductHeap(null, 0);
 }
예제 #2
0
파일: Model.cs 프로젝트: agentydragon/IVU
 public void AddToStart(Product product, int count)
 {
     StartContents = new ProductHeap(new ProductInstance(product, 0), count);
     if (NoOrders)
     {
         Dispatch();
     }
 }
예제 #3
0
파일: Model.cs 프로젝트: agentydragon/IVU
 public void Clear()
 {
     Contents = new ProductHeap(null, 0);
     if (Cleared != null)
     {
         Cleared();
     }
 }
예제 #4
0
파일: Model.cs 프로젝트: agentydragon/IVU
        public Model()
        {
            double coordinateMultiplierX = 2, coordinateMultiplierY = 1.7;

            context = SynchronizationContext.Current;
            if (context == null)
            {
                context = new SynchronizationContext();
            }

            CarrierPath = new Queue <PathNode>();
            products    = new BindingList <Product>();
            workplaces  = new List <Workplace> {
                new Workplace(201, new Point(50, 50), context),
                new Workplace(202, new Point(200, 50), context),
                new Workplace(203, new Point(350, 50), context),
                new Workplace(204, new Point(50, 200), context),
                new Workplace(205, new Point(200, 200), context),
                new Workplace(300, new Point(350, 200), context),
                new Workplace(401, new Point(50, 350), context),
                new Workplace(402, new Point(200, 350), context),
                new Workplace(600, new Point(350, 350), context),
                new Workplace(900, new Point(500, 350), context)
            };

            foreach (Workplace w in Workplaces)
            {
                w.Location = new Point((int)(w.Location.X * coordinateMultiplierX), (int)(w.Location.Y * coordinateMultiplierY));
            }

            swapspaces = new List <Swapspace>
            {
                new Swapspace(new Point(200, 500), context),
                new Swapspace(new Point(650, 125), context)
            };

            foreach (Swapspace s in Swapspaces)
            {
                s.Location = new Point((int)(s.Location.X * coordinateMultiplierX), (int)(s.Location.Y * coordinateMultiplierY));
            }

            carrierContents = new ProductHeap(null, 0);
            CarrierPosition = new Point((int)(125 * coordinateMultiplierX), (int)(50 * coordinateMultiplierY));
            startContents   = new ProductHeap(null, 0);
            endPoints       = new EndPoint[2];
            endPoints[0]    = new EndPoint(new Point(50, 500), context);
            endPoints[1]    = new EndPoint(new Point(350, 500), context);

            foreach (EndPoint e in endPoints)
            {
                e.Location = new Point((int)(e.Location.X * coordinateMultiplierX), (int)(e.Location.Y * coordinateMultiplierY));
                e.Cleared += new EndPointClearedHandler(EndpointCleared);
            }

            StartLocation = new Point((int)(500 * coordinateMultiplierX), (int)(50 * coordinateMultiplierY));

            PathNodes = new PathNode[] {
                new PathNode(0, 50, 50), new PathNode(1, 125, 50), new PathNode(2, 200, 50), new PathNode(3, 350, 50), new PathNode(4, 500, 50),
                new PathNode(5, 125, 125), new PathNode(6, 200, 125), new PathNode(7, 275, 125), new PathNode(8, 350, 125), new PathNode(9, 500, 125),
                new PathNode(10, 50, 200), new PathNode(11, 125, 200), new PathNode(12, 200, 200), new PathNode(13, 350, 200),
                new PathNode(14, 125, 275), new PathNode(15, 275, 275),
                new PathNode(16, 50, 350), new PathNode(17, 125, 350), new PathNode(18, 200, 350), new PathNode(19, 275, 350), new PathNode(20, 350, 350), new PathNode(21, 500, 350),
                new PathNode(22, 50, 500), new PathNode(23, 125, 500), new PathNode(24, 275, 500), new PathNode(25, 350, 500),
                new PathNode(26, 200, 500), new PathNode(27, 650, 125)
            };

            foreach (PathNode n in PathNodes)
            {
                n.Location = new Point((int)(n.Location.X * coordinateMultiplierX), (int)(n.Location.Y * coordinateMultiplierY));
            }

            int[,] tmp = new int[, ] {
                { 0, 1 }, { 1, 5 }, { 5, 6 }, { 2, 6 }, { 6, 7 }, { 7, 8 }, { 3, 8 }, { 8, 9 }, { 9, 4 },
                { 10, 11 }, { 5, 11 }, { 6, 12 }, { 7, 15 }, { 8, 13 }, { 11, 14 },
                { 14, 17 }, { 16, 17 }, { 17, 23 }, { 14, 15 }, { 19, 20 }, { 19, 24 },
                { 22, 23 }, { 24, 25 }, { 9, 21 }, { 15, 19 }, { 18, 19 },
                { 23, 26 }, { 24, 26 }, { 9, 27 }
            };

            PathEdges = new PathEdge[tmp.GetLength(0)];
            for (int i = 0; i < tmp.GetLength(0); i++)
            {
                PathEdges[i] = new PathEdge(PathNodes[tmp[i, 0]], PathNodes[tmp[i, 1]]);
            }

            foreach (PathEdge e in PathEdges)
            {
                e.A.AdjacentEdges.Add(e);
                e.B.AdjacentEdges.Add(e);
            }

            foreach (Workplace w in Workplaces)
            {
                w.Finished += new EventHandler((a, b) => { Dispatch(); });
            }
        }
예제 #5
0
파일: Model.cs 프로젝트: agentydragon/IVU
 public EndPoint(Point location, SynchronizationContext context)
 {
     contents      = new ProductHeap(null, 0);
     this.location = location;
     this.context  = context;
 }
예제 #6
0
파일: Model.cs 프로젝트: agentydragon/IVU
 public Swapspace(Point location, SynchronizationContext context)
 {
     this.context = context;
     Location     = location;
     contents     = new ProductHeap(null, 0);
 }
예제 #7
0
파일: Model.cs 프로젝트: agentydragon/IVU
        // 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);
        }
예제 #8
0
파일: Model.cs 프로젝트: agentydragon/IVU
 protected bool CanDealWith(ProductHeap heap)
 {
     return((heap.IsFinished && (FreeEndpointExists() || FreeSwapspaceExists())) || ((!heap.IsFinished) && (Workplaces[heap.Product.Product.Actions[heap.Product.Job].Place].Contents.Empty || FreeSwapspaceExists())));
 }