Beispiel #1
0
        SeasonPlannerForOptimizer GetInitialSeasonPlannerOptimizer()
        {
            SeasonPlannerForOptimizer spOptimizer = new SeasonPlannerForOptimizer();

            spOptimizer.Id                = 1;
            spOptimizer.car               = ReadCarFromForm();
            spOptimizer.driver            = ReadDriverFromForm();
            spOptimizer.raceTab           = ReadRaceTabFromForm();
            spOptimizer.staffFacilities   = ReadSfFromForm();
            spOptimizer.technicalDirector = ReadTdFromForm();

            return(spOptimizer);
        }
Beispiel #2
0
        //Form1 objects
        void bttSpOptimize_Click(object sender, EventArgs e)
        {
            finishedLoading = false;
            Random random = new Random();

            int nRuns        = int.Parse(txtSpNumberTries.Text);
            int targetPoints = int.Parse(txtSpTargetPoints.Text);

            //Get Initial Values / SP Line
            SeasonPlannerForOptimizer spOptimizer = new SeasonPlannerForOptimizer();

            spOptimizer = GetInitialSeasonPlannerOptimizer();
            SeasonPlannerForDataTable spTable = new SeasonPlannerForDataTable();

            spTable.SeasonRaceNumber = cBoxNextRacingTrack.SelectedIndex;
            spTable.TrackId          = spOptimizer.raceTab.SeasonTrackIndex; //-1?
            //SeasonPlannerTab spTab = new SeasonPlannerTab();
            //spTab = ReadSeasonPlannerTabFromForm();
            int initialRaceId = spTable.SeasonRaceNumber;

            SeasonPlannerFullLine spFull = GetInitialSpFull();

            //spFull2.spTable = spTable;
            //SeasonPlannerFullLine spFull = new SeasonPlannerFullLine(new SeasonPlannerDecision(), spTable, spOptimizer, spTab);

            //Process
            processingForm = new Processing(nRuns);
            processingForm.Show();
            //spDecisions = GetBestDecisions(nRuns, spTable.SeasonRaceNumber, random, spFull, targetPoints, maxBalance);

            GetBestDecisionsAsync(nRuns, spTable.SeasonRaceNumber, spFull, targetPoints);
            //SeasonPlannerDecision[] spDecisions = ReadSpDecisionsFromDgv();

            //finishedLoading = true;

            ////Update Values when process completes
            //dgvSp_CellValueChanged(null, null);
        }
Beispiel #3
0
        SeasonPlannerFullLine GetInitialSpFull()
        {
            SeasonPlannerFullLine spFull = new SeasonPlannerFullLine();

            SeasonPlannerDecision[] spDecisions = DB.SeasonPlannerTab.ReadSpDecisionsFromDB(0);

            SeasonPlannerForOptimizer spOptimizer = new SeasonPlannerForOptimizer();
            RaceTab rTab = DB.RaceTab.ReadRaceTabFromDB();

            spOptimizer.raceTab = rTab;
            SeasonPlannerTab spTab = DB.SeasonPlannerTab.ReadSeasonPlannerTabFromDB();

            spOptimizer.spTab = spTab;
            StaffFacilities sf = DB.StaffFacilities.ReadStaffFacilitiesFromDB();

            spOptimizer.staffFacilities = sf;
            TechnicalDirector td = DB.TechnicalDirector.ReadTdFromDB();

            spOptimizer.technicalDirector = td;
            Driver driver = DB.Driver.ReadDriverFromDB();

            spOptimizer.driver = driver;
            Car car = DB.Car.ReadCarFromDB();

            spOptimizer.car = car;

            SeasonPlannerForDataTable spTable = new SeasonPlannerForDataTable();

            spTable.BalanceAfterRaceM = spTab.StartingBalanceM;

            spFull.spTable     = spTable;
            spFull.spOptimizer = spOptimizer;
            spFull.spTab       = spTab;
            spFull.spDecisions = spDecisions[0];

            return(spFull);
        }
Beispiel #4
0
        static internal SeasonPlannerFullLine ProcessSeasonPlanner(SeasonPlannerFullLine spFull)
        {
            #region  Initial Values
            Classes.RaceTab rt = spFull.spOptimizer.raceTab;
            Classes.SeasonPlannerForDataTable spForDataTable = spFull.spTable; //null. Filled later
            Classes.TechnicalDirector         td             = spFull.spOptimizer.technicalDirector;
            Classes.Car             car          = (Classes.Car)spFull.spOptimizer.car.Clone();
            Classes.Car             carAfterRace = (Classes.Car)car.Clone();
            Classes.Driver          driver       = spFull.spOptimizer.driver;
            int                     trackId      = DB.SeasonTrack.GetTrackId(spFull.spTable.SeasonRaceNumber);
            Classes.Track           track        = DB.Track.ReadTrackFromDB(trackId);
            Classes.StaffFacilities sf           = spFull.spOptimizer.staffFacilities;
            Classes.TyresSupplier   tyre         = DB.Tyres.ReadActiveTyreSupplierFromDB();

            int seasonRaceNumber = rt.SeasonTrackIndex;
            //float balanceM = spFull.spTab.StartingBalanceM;
            float balanceM       = spFull.spTable.BalanceAfterRaceM;
            int[] carPartsBought = new int[11];

            Divisions division = (Divisions)spFull.spTab.Division;

            int  trainning       = (int)spFull.spDecisions.Training;
            bool testing         = spFull.spDecisions.Testing;
            int  targetCarLevel  = spFull.spDecisions.TargetCarLevelEngBra;
            int  targetCarLevel2 = spFull.spDecisions.TargetCarLevelOthers;
            int  ct = spFull.spDecisions.CT;
            #endregion

            #region Process
            carAfterRace.UpdateCarWearAfterRace(track, driver, ct);

            if (testing)
            {
                carAfterRace.DoTesting(td, track, sf);
            }
            carPartsBought = GetWhichCarPartsChange(car, carAfterRace, targetCarLevel, targetCarLevel2);

            carAfterRace = (Classes.Car)car.Clone();
            carAfterRace = GetCarAfterPartsChangeAndWear(car, testing, track, driver, td, sf, ct, carPartsBought);

            int qualPosition = SpHelper.GetQualPosition(driver, car, division);
            int racePosition = SpHelper.GetRacePosition(driver, car, division, ct);
            int racePoints   = SpHelper.GetPoints(racePosition);

            //Expenses processing
            float balanceAfterRaceM = ((balanceM * 1000000) + GetAfterRaceBalance(driver, td, sf, testing, tyre, car, division, qualPosition, racePosition, trainning, carPartsBought)) / 1000000f;
            #endregion

            #region Output
            SeasonPlannerDecision spDecisionsNext = new SeasonPlannerDecision();
            spDecisionsNext = (Classes.SeasonPlannerDecision)spFull.spDecisions.Clone();

            SeasonPlannerForDataTable spTableNext = new SeasonPlannerForDataTable();
            spTableNext.SeasonRaceNumber  = spFull.spTable.SeasonRaceNumber + 1;
            spTableNext.BalanceAfterRaceM = balanceAfterRaceM;
            spTableNext.CarPartsChanged   = carPartsBought;
            spTableNext.CarWearAfterRace  = carAfterRace.GetWears();
            spTableNext.QualPosition      = qualPosition;
            spTableNext.RacePosition      = racePosition;

            SeasonPlannerForOptimizer spOptimizerNext = new SeasonPlannerForOptimizer();
            spOptimizerNext.car = (Classes.Car)carAfterRace.Clone();

            driver.DoTrainning((DriverTrainning)trainning);
            driver.DriverUpdateAfterRace(racePosition);
            spOptimizerNext.driver            = driver;
            spOptimizerNext.Id                = spFull.spOptimizer.Id + 1;
            spOptimizerNext.raceTab           = rt; //How to update trackId?
            spOptimizerNext.staffFacilities   = sf; //To Do: Update sf after races (convert levels to float type)
            spOptimizerNext.technicalDirector = td;

            SeasonPlannerTab spTabNext = new SeasonPlannerTab();
            spTabNext.CurrentPoints    = spFull.spTab.CurrentPoints + racePoints;
            spTabNext.Division         = spFull.spTab.Division;
            spTabNext.StartingBalanceM = balanceAfterRaceM;
            spTabNext.TargetPoints     = spFull.spTab.TargetPoints;

            SeasonPlannerFullLine spFullNext = new SeasonPlannerFullLine(spDecisionsNext, spTableNext, spOptimizerNext, spTabNext);

            return(spFullNext);

            #endregion
        }