/// <summary>
        /// Initializes shipment - sets number of levels, clears space on the ship.
        /// </summary>
        /// <param name="shipId">For which ship the shipment will be considered.</param>
        /// <param name="containerHeight">Constant value of height of containers in this shipment.</param>
        public Shipment(int shipId, int containerHeight)
        {
            containerLocationsList = new List <ContainerLocation>();
            var shipService = new ShipService();

            ship     = shipService.GetShipById(shipId);
            noLevels = ship.height / containerHeight;
            ClearSpace();
        }
Esempio n. 2
0
        /// <summary>
        /// Adds new ship and refreshes the form view.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button4_Click(object sender, EventArgs e)
        {
            var shipService = new ShipService();

            shipService.AddNewShip();
            Controls.Clear();
            InitializeComponent();
            MessageBox.Show("Ship added succesfully", "ShipAdd", MessageBoxButtons.OK);
            //button2_Click(sender, e);
        }
Esempio n. 3
0
        /// <summary>
        /// Generates containers and ships sets of data after clicking the button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            var containerService = new ContainerService();

            containerService.GenerateContainerSets(new List <int>()
            {
                100, 60, 30
            });
            var shipService = new ShipService();

            shipService.GenerateShipSet();

            Controls.Clear();
            InitializeComponent();
            MessageBox.Show("Data generated succesfully", "Save", MessageBoxButtons.OK);
        }
Esempio n. 4
0
        /// <summary>
        /// Determines which ship will be the best choice to send containers in.
        /// </summary>
        /// <param name="containersList"></param>
        /// <param name="algorithm"></param>
        /// <param name="shipment"></param>
        /// <returns>List of containers the haven't been sent yet.</returns>
        private List <Container> ChooseTheShipAndSendIt(List <Container> containersList, int algorithm, out Shipment shipment)
        {
            var containerHeight             = containersList.First().height;
            List <Container> containersLeft = new List <Container>();
            List <Ship>      shipsList      = new ShipService().GetShipsList();
            var bestShipId          = 0;
            var prevContainersCount = Int32.MaxValue;

            foreach (var item in shipsList)
            {
                shipment       = new Shipment(item.id, containerHeight);
                containersLeft = shipment.FillTheShip(containersList, algorithm);
                if (containersLeft.Count < prevContainersCount)
                {
                    bestShipId          = item.id;
                    prevContainersCount = containersLeft.Count;
                }
            }
            shipment       = new Shipment(bestShipId, containerHeight);
            containersLeft = shipment.FillTheShip(containersList, algorithm);

            return(containersLeft);
        }