Esempio n. 1
0
        private Problem problem; //problem associated with this cowboy

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Sets up the cowboy with a random location
        /// </summary>
        /// <param name="problem">The problem the cowboy is a potential solution to</param>
        public Cowboy(Problem problem)
        {
            this.problem = problem;
            Random r = problem.Random;
            location = new decimal[] { (decimal)(r.Next(Problem.SizeX) + r.NextDouble()), (decimal)(r.Next(Problem.SizeY) + r.NextDouble()) };
            checkLocation();
        }
Esempio n. 2
0
 /// <summary>
 /// Initialises the solution and associates it with a specified problem.
 /// </summary>
 /// <param name="problem">The problem to associate this solution with</param>
 public Solution(Problem problem)
 {
     this.problem = problem;
     cowboys = new Cowboy[Problem.NumCowboys];
     for (int i = 0; i < Problem.NumCowboys; i++)
     {
         cowboys[i] = new Cowboy(problem);
     }
     checkCowboys();
 }
Esempio n. 3
0
 /// <summary>
 /// The write class writes the important information about a problem to the console
 /// </summary>
 /// <param name="p">The problem to write to the console</param>
 /// <param name="title">The title to begin the section with</param>
 private static void write(Problem p, string title)
 {
     int i = title.Length;
     string topBottom = "";
     for (int j = 0; j < i + 6; j++)
     {
         topBottom += "X";
     }
     Console.WriteLine(topBottom);
     Console.WriteLine("XX " + title + " XX");
     Console.WriteLine(topBottom);
     Console.WriteLine();
     Solution t = p.getBestNumAlive();
     Console.WriteLine("Number alive (Best): " + t.getNumAlive());
     Console.WriteLine("Visibility (Best): " + p.getBestVisibility().getVisibility());
     Console.WriteLine("Improvement: Number Alive (Best): " + (t.getNumAlive() - p.InitialBestAlive));
     Console.WriteLine("Improvement: Visibility (Best): " + (p.getBestVisibility().getVisibility() - p.InitialBestVisibility));
     if (p.Solutions.Count != 1)
     {
         Console.WriteLine("_________________________________________________________");
         Console.WriteLine("Number alive (Mean): " + p.getAvgNumAlive());
         Console.WriteLine("Visibility (Mean): " + p.getAvgVisibility());
         Console.WriteLine("Improvement: Number Alive (Mean): " + (p.getAvgNumAlive() - p.InitialAvgAlive));
         Console.WriteLine("Improvement: Visibility (Mean): " + (p.getAvgVisibility() - p.InitialAvgVis));
        /* Console.WriteLine("_________________________________________________________");
         Console.WriteLine("Number Alive (Final Set):");
         foreach (Solution s in p.Solutions)
         {
             Console.Write(s.getNumAlive() + ", ");
         }
         Console.WriteLine();
         Console.WriteLine("Visibility (Final Set):");
         foreach (Solution s in p.Solutions)
         {
             Console.Write(s.getVisibility() + ", ");
         }
         Console.WriteLine();*/
     }
     Console.WriteLine("=========================================================");
     Console.WriteLine();
 }
Esempio n. 4
0
 /// <summary>
 /// An overloaded constructor that allows the specification of the points of the obstacle,
 /// as well as the problem it is related to.
 /// </summary>
 /// <param name="problem">The problem this obstacle is related to</param>
 /// <param name="points">The points that make up the vertices of this object</param>
 public Obstacle(Problem problem, decimal[,] points)
 {
     this.problem = problem;
     this.points = points;
 }
Esempio n. 5
0
 /// <summary>
 /// Sets up the obstacle with a semi random number of sides
 /// </summary>
 /// <param name="problem">The problem this obstacle is related to</param>
 public Obstacle(Problem problem)
 {
     this.problem = problem;
     points = new decimal[Problem.ObstSides, 2];
     //add random init code
 }
Esempio n. 6
0
 /// <summary>
 /// Initialises the solution providing it the list of cowboys and the problem to
 /// be associated with
 /// </summary>
 /// <param name="problem">The problem to associate this solution with</param>
 /// <param name="cowboys">The list of cowboys to use for this solution</param>
 public Solution(Problem problem, Cowboy[] cowboys)
 {
     this.problem = problem;
     this.cowboys = cowboys;
     checkCowboys();
 }
Esempio n. 7
0
 /// <summary>
 /// An overloaded constructor for the cowboy that allows its location to be specified.
 /// </summary>
 /// <param name="problem">The problem the cowboy is a potential solution to</param>
 /// <param name="location">The desired location for the cowboy</param>
 public Cowboy(Problem problem, decimal[] location)
 {
     this.problem = problem;
     this.location = location;
     checkLocation();
 }