コード例 #1
0
ファイル: Restaurant.cs プロジェクト: toblotron/TablePut
        public Restaurant(int nrTables, int maxTime)
        {
            NrTables = nrTables;
            MaxTime  = maxTime;

            var random = new Random();

            Tables = new ObservableCollection <Table>();
            for (int i = 0; i < nrTables; i++)
            {
                Tables.Add(new Table {
                    Id = i, Size = random.Next(4) + 2
                });
            }

            // generate virtual tables - allow up to 5 adjecent tables to be a virtual table
            VirtualTables = new ObservableCollection <VirtualTable>();

            int vtID = 0;

            for (int t = 0; t < Tables.Count(); t++)
            {
                int smallest = 100;
                for (int s = 0; s < 5 && s + t < Tables.Count(); s++)
                {
                    ObservableCollection <Table> tables = new ObservableCollection <Table>();
                    for (int tnr = t; tnr < t + s + 1; tnr++)
                    {
                        if (Tables[tnr].Size < smallest)
                        {
                            smallest = Tables[tnr].Size;
                        }

                        tables.Add(Tables[tnr]);
                    }
                    VirtualTable vt = new VirtualTable(tables, vtID, smallest);
                    vtID++;
                    VirtualTables.Add(vt);

                    // build vtDict
                    // - reasonable (non wasteful) vt's for each {nr of guests}
                    for (int dictKey = vt.Smallest; dictKey <= vt.Capacity; dictKey++)
                    {
                        // add this vt to the dicts where it fits
                        ObservableCollection <VirtualTable> tablesOfCapacity = null;
                        if (vtDict.Keys.Contains(vt.Capacity))
                        {
                            tablesOfCapacity = vtDict[vt.Capacity];
                        }
                        else
                        {
                            tablesOfCapacity = new ObservableCollection <VirtualTable>();
                            vtDict.Add(vt.Capacity, tablesOfCapacity);
                        }
                        tablesOfCapacity.Add(vt);
                    }
                }
            }
        }
コード例 #2
0
        // if there is a solution available that has 0 objections, take it and
        // replace the current BookingAssignments with those in that solution
        public bool AdaptAdequateSolution()
        {
            bool result = false;

            Chromosome winner = solver.population.First();

            if (winner.fitness == 0)
            {
                Assignments = new ObservableCollection <BookingAssignment>();
                int geneNr = 0;
                foreach (Booking booking in GoalBookings)
                {
                    VirtualTable vt = Restaurant.VirtualTables[winner.VirtualTableIds[geneNr]];
                    foreach (int tableIndex in vt.TableIds)
                    {
                        Table Table = Restaurant.Tables[tableIndex];
                        Assignments.Add(new BookingAssignment()
                        {
                            TableId = tableIndex, BookingId = booking.Id
                        });                                                                                        // kan bli fel! - vi kör inte med ostörd mängd bokningar!
                    }
                    geneNr++;
                }

                /*
                 * foreach(int vtId in winner.VirtualTableIds)
                 * {
                 *  VirtualTable vt = Restaurant.VirtualTables[vtId];
                 *  foreach (int tableIndex in vt.TableIds)
                 *  {
                 *      Table Table = Restaurant.Tables[tableIndex];
                 *      Assignments.Add(new BookingAssignment() { TableId = tableIndex, BookingId = bookingId }); // kan bli fel! - vi kör inte med ostörd mängd bokningar!
                 *  }
                 *  bookingOrder++;
                 * }*/

                this.OnPropertyChanged("Assignments");
            }

            return(result);
        }