Beispiel #1
0
		static void Main(string[] args)
		{
            // Use stopwatch to time the program
            Stopwatch stopwatch = Stopwatch.StartNew();
            
            // Read the names of the people from a text file
			StreamReader streamReader = new StreamReader("People1.txt");

            // The first line holds the total number of people
			int numberOfPeople = int.Parse(streamReader.ReadLine());

            // The next lines hold the names of the people
            // Add the people to the Person list
			for (int counter = 0; counter < numberOfPeople; counter++)
			{
				Person person = new Person(streamReader.ReadLine().Split('.')[1]);
				People.Add(person);
			}

            // Read in the preferences from a text file
            streamReader = new StreamReader("Preferences1.txt");
			for (int personNumber = 0; personNumber < People.Count; personNumber++)
			{
                // Use findPerson to find the person that the preferences are about
				Person person = findPerson(streamReader.ReadLine());

                // Loop through the next couple lines to read the data of the preferences
				for (int counter = 0; counter < NUM_PREFERENCES; counter++)
				{

					string name = streamReader.ReadLine().Split('.')[1];
					person.Preferences.Add(findPerson(name));
				}
			}

            List<List<Person>> permutations = Permutations(People).ToList<List<Person>>();
            int Maximum = Int32.MinValue;
            List<Room> BestRooms = new List<Room>();
            foreach(List<Person> people in permutations)
            {
                List<Room> rooms = PermutationToRooms(people);
                int score = ListRoomScore(rooms);
                if (score > Maximum)
                {
                    Maximum = score;
                    BestRooms = rooms;
                }
            }
            foreach (Room room in BestRooms)
            {
                Console.WriteLine(room.ToString());
            }
            stopwatch.Stop();
            Console.WriteLine(stopwatch.ElapsedMilliseconds);
            Console.ReadLine();
		}
Beispiel #2
0
		// Gives how much the first person likes the second person
		public int preference(Person firstPerson, Person secondPerson)
		{
			for (int counter = 0; counter < firstPerson.Preferences.Count; counter++)
			{
				Person person = firstPerson.Preferences[counter];
				if (person.Equals(secondPerson))
					return 5 - counter;
			}
			return 0;
		}