public RequestDelivery(ClientController clientCon, ClientState clientState)
        {
            InitializeComponent();
            var state = new CurrentState();
            var routeService = new RouteService(state);
            _pathFinder = new PathFinder(routeService);
            _clientState = clientState;
            _pathfindService = new DeliveryService(state, _pathFinder);
            _clientController = clientCon;

            foreach (var routeNode in clientState.GetAllRouteNodes())
            {
                ComboBoxItem cbi = new ComboBoxItem();
                if (routeNode is DistributionCentre)
                    cbi.Content = ((DistributionCentre)routeNode).Name;
                else if (routeNode is InternationalPort)
                    cbi.Content = routeNode.Country.Name;
                cbi.Tag = routeNode.ID;
                this.origin.Items.Add(cbi);

                ComboBoxItem cbi2 = new ComboBoxItem();
                if (routeNode is DistributionCentre)
                    cbi2.Content = ((DistributionCentre)routeNode).Name;
                else if (routeNode is InternationalPort)
                    cbi2.Content = routeNode.Country.Name;
                cbi2.Tag = routeNode.ID;
                this.destination.Items.Add(cbi2);
            }

            _clientController.OptionsReceived += new ClientController.DeliveryOptionsDelegate(DeliveryOptions_Returned);
            _clientController.DeliveryOK+= new ClientController.DeliveryConfirmedDelegate(DeliveryConfirmed);
        }
        public static void MyClassInitialize(TestContext testContext)
        {
            var currentState = new CurrentState();
            currentState.InitialiseRoutes(getRoutes());

            routeService = new RouteService(currentState);
        }
        public static void MyClassInitialize(TestContext testContext)
        {
            var countries = new Dictionary<int,Country> {{1, new Country {Name = "New Zealand", Code = "NZ", ID = 1}}};

            state = new CurrentState();
            state.InitialiseCountries(countries);
            state.InitialiseRouteNodes(new Dictionary<int, RouteNode>());
            service = new CountryService(state);

            new Database("test.db");
        }
示例#4
0
        static void Main(string[] args)
        {
            //hashedSolutions = (Dictionary<Tuple<int, int>, Solution>)SystemLog.OpenSavedObject();

            CurrentState state = new CurrentState(2, 10);
            Console.WriteLine("Worst case: " + (state.WorstCase().WorstCase.ToString()));
            for (int i = 0; i < state.GlobalDropHeights.Count(); i++) {
                Console.WriteLine(state.GlobalDropHeights[i].ToString());
            }

            //hashedSolutions.SerializeAndSave();
            Console.ReadLine();
        }
        public EventService(CurrentState state)
        {
            dataHelper = new EventDataHelper();
            this.state = state;

            if (!state.EventsInitialised())
            {
                int currentNumberOfEvents = dataHelper.GetNumberOfEvents();
                if (currentNumberOfEvents != 0)
                {
                    state.SetNumberOfEvents(currentNumberOfEvents);
                }
            }
        }
        public static void MyClassInitialize(TestContext testContext)
        {
            // initialise state
            CurrentState state = new CurrentState();
            routeNodes = new List<RouteNode>();
            routeNodes.Add(new DistributionCentre("Christchurch"));
            routeNodes.Add(new DistributionCentre("Wellington"));
            routeNodes.Add(new DistributionCentre("Auckland"));

            routes = getRoutes(routeNodes);

            state.InitialiseRoutes(getRoutes(routeNodes));

            // initialise routeService
            var routeService = new RouteService(state);

            // initialise pathfinder
            pathFinder = new PathFinder(routeService);
        }
示例#7
0
            public Solution WorstCase()
            {
                depthCounter++;
                List<int> localDropHeights = new List<int>();
                int worstCaseToReturn = int.MinValue;
                if (hashedSolutions.ContainsKey(state())) {
                    var drop = hashedSolutions[state()];
                    localDropHeights.AddRange(drop.DropHeights);
                    worstCaseToReturn = drop.WorstCase;
                }
                if (N == 1) {
                    worstCaseToReturn = 0;
                }
                if (N == 2) {
                    worstCaseToReturn = 2;
                    localDropHeights.Add(1);
                }
                if (M == 1) {
                    worstCaseToReturn = N + 1;
                    for (int i = 1; i < N + 1; i++)
                        localDropHeights.Add(i);
                }
                if (worstCaseToReturn == int.MinValue) {
                    int bestWorstCaseDrops = int.MaxValue;
                    int bestWorstCaseFloor = 0;
                    for (int dropFloor = 1; dropFloor < N / 2 + 1; dropFloor++) {
                        var breakScenario = new CurrentState(M - 1, dropFloor).WorstCase();
                        int breakScenarioTrials = breakScenario.WorstCase + 2;
                        var surviveScenario = new CurrentState(M, N - dropFloor).WorstCase();
                        int surviveScenarioTrials = breakScenario.WorstCase + 1;
                        int temp = 0;
                        if (breakScenarioTrials < surviveScenarioTrials) {
                            temp = surviveScenarioTrials;
                            localDropHeights.AddRange(surviveScenario.DropHeights);
                        } else {
                            temp = breakScenarioTrials;
                            localDropHeights.AddRange(breakScenario.DropHeights);
                        }

                        if (temp < bestWorstCaseDrops) {
                            bestWorstCaseDrops = temp;
                            bestWorstCaseFloor = dropFloor;
                        }
                    }
                    localDropHeights.Add(bestWorstCaseFloor);
                    hashedSolutions.Add(state(), new Solution(bestWorstCaseDrops, localDropHeights));
                    worstCaseToReturn = bestWorstCaseDrops;
                }
                if (depthCounter-- == 1)
                    GlobalDropHeights.AddRange(localDropHeights);
                if (worstCaseToReturn == int.MinValue || worstCaseToReturn == int.MaxValue)
                    throw new Exception();
                return new Solution(worstCaseToReturn, localDropHeights);
            }
示例#8
0
        public void SetUpHome()
        {
            // initialise network
            Network network = Network.Instance;
            network.BeginConnect("localhost", 8080);

            // initialise database
            Database.Instance.Connect();

            // initialise all the services (they set up the state themselves)

            _currentState = new CurrentState();

            //set up Columns in all of the DataGrids
            countriesList.Columns.Add(new DataGridTextColumn { Header = "ID", Binding = new Binding("ID") });
            countriesList.Columns.Add(new DataGridTextColumn { Header = "Name", Binding = new Binding("Name") });
            countriesList.Columns.Add(new DataGridTextColumn { Header = "Code", Binding = new Binding("Code") });

            companiesList.Columns.Add(new DataGridTextColumn { Header = "ID", Binding = new Binding("ID") });
            companiesList.Columns.Add(new DataGridTextColumn { Header = "Name", Binding = new Binding("Name") });

            distCenterList.Columns.Add(new DataGridTextColumn { Header = "ID", Binding = new Binding("ID") });
            distCenterList.Columns.Add(new DataGridTextColumn { Header = "Name", Binding = new Binding("Name") });

            routesList.Columns.Add(new DataGridTextColumn { Header = "ID", Binding = new Binding("ID") });
            routesList.Columns.Add(new DataGridTextColumn { Header = "Origin", Binding = new Binding("Origin") });
            routesList.Columns.Add(new DataGridTextColumn { Header = "Destination", Binding = new Binding("Destination") });
            routesList.Columns.Add(new DataGridTextColumn { Header = "Company", Binding = new Binding("Company") });
            routesList.Columns.Add(new DataGridTextColumn { Header = "TransportType", Binding = new Binding("TransportType") });

            domesticPriceList.Columns.Add(new DataGridTextColumn { Header = "ID", Binding = new Binding("ID") });
            domesticPriceList.Columns.Add(new DataGridTextColumn { Header = "Priority", Binding = new Binding("Priority") });
            domesticPriceList.Columns.Add(new DataGridTextColumn { Header = "Price per gram", Binding = new Binding("PricePerGram") });
            domesticPriceList.Columns.Add(new DataGridTextColumn { Header = "Price per cm^3", Binding = new Binding("PricePerCm3") });

            intlPriceList.Columns.Add(new DataGridTextColumn { Header = "ID", Binding = new Binding("ID") });
            intlPriceList.Columns.Add(new DataGridTextColumn { Header = "Origin", Binding = new Binding("Origin") });
            intlPriceList.Columns.Add(new DataGridTextColumn { Header = "Destination", Binding = new Binding("Destination") });
            intlPriceList.Columns.Add(new DataGridTextColumn { Header = "Priority", Binding = new Binding("Priority") });
            intlPriceList.Columns.Add(new DataGridTextColumn { Header = "Price per gram", Binding = new Binding("PricePerGram") });
            intlPriceList.Columns.Add(new DataGridTextColumn { Header = "Price per cm^3", Binding = new Binding("PricePerCm3") });

            intlPortList.Columns.Add(new DataGridTextColumn { Header = "ID", Binding = new Binding("ID") });
            intlPortList.Columns.Add(new DataGridTextColumn { Header = "Country", Binding = new Binding("Country") });
        }
示例#9
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            // initialise logger
            Logger.Instance.SetOutput(logBox);
            Logger.WriteLine("Server starting..");

            // initialise database
            Database.Instance.Connect();

            // initialise the state object
            currentState = new CurrentState();

            // initialise all the services (they set up the state themselves) and pathfinder
            countryService = new CountryService(currentState);
            companyService = new CompanyService(currentState);
            routeService = new RouteService(currentState);
            var pathFinder = new PathFinder(routeService); // pathfinder needs the RouteService and state
            deliveryService = new DeliveryService(currentState, pathFinder); // DeliveryService needs the PathFinder
            priceService = new PriceService(currentState);
            locationService = new LocationService(currentState);
            eventService = new EventService(currentState);
            statisticsService = new StatisticsService();

            // initialise network
            Network.Network network = Network.Network.Instance;
            network.Start();
            network.Open();

            // create controller
            var controller = new Controller(countryService, companyService, deliveryService, priceService, routeService,
                                            locationService, statisticsService, eventService);

            //BenDBTests(countryService, routeService);
            //SetUpDatabaseWithData();

            /*try
            {
                var priceDH = new PriceDataHelper();

                var standardPrice = new DomesticPrice(Priority.Standard) { PricePerGram = 3, PricePerCm3 = 5 };
                //standardPrice = priceService.CreateDomesticPrice(standardPrice.Priority, standardPrice.PricePerGram, standardPrice.PricePerCm3);

                standardPrice.PricePerCm3 = 8;
                //standardPrice = priceService.UpdateDomesticPrice(standardPrice.ID, standardPrice.Priority, standardPrice.PricePerGram, standardPrice.PricePerCm3);

                var loadedPrice = priceService.GetDomesticPrice(1);
                var prices = priceService.GetAllDomesticPrices();

                var normalPrices = priceService.GetAll();
            }
            catch (DatabaseException er) {
                Logger.WriteLine(er.Message);
                Logger.Write(er.StackTrace);
            }*/
        }