
/**************************************************************************************************/
/*                                                                                                */
/*  Name:  DarC KonQuesT                                                                          */
/*  Program:  #5                                                                                  */
/*  Date:  2005.12.09                                                                             */
/*  Purpose:                                                                                      */
/*      Collect input for the network then insert it into network, call function to output        */
/*  initial state, then call function to find the correct path (if existent)                      */
/*                                                                                                */
/*                                                                                                */
/**************************************************************************************************/

#include <iostream>
#include <string>
#include "network.h"
#include <iomanip>

using namespace std;


/*  Name: outputNetwork(network<string>& my_network)                                                                  */
/*  Purpose: output initial state of network                                                                          */
/*  Parameters:  network<string>& my_network                                                                          */
/*  Preconditions:  my_network correctly initialized/filled                                                           */
/*  Postconditions:  network initial state output to cout.                                                            */
void outputNetwork(network<string>& my_network) {

      network<string>::iterator itr;
      list< string >::iterator list_itr;
      string v1;
      
      cout << endl << "The initial state is as follows: " << endl;
      for (itr = my_network.begin(); itr != my_network.end(); itr++)
      {
        v1 = (*itr).first;
        list<string> my_list = my_network.get_neighbor_list (v1);
        for (list_itr = my_list.begin(); list_itr != my_list.end(); list_itr++)
        {
          cout << v1 << " " << *list_itr << " " << fixed << showpoint << setprecision(1) << my_network.get_edge_weight(v1, *list_itr) << endl;
        }
      } // printing each edge in my_network^M
      cout << endl;
}


/*  Name:   main()                                                                                                    */
/*  Purpose: handles input of vertices and passes them into a network                                                 */
/*  Parameters: none                                                                                                  */
/*  Preconditions: none                                                                                               */
/*  Postconditions:  network has been filled, output, and checked for a correct path (after function calls)           */
int main()
{
  network<string> cities;
  
  string c1, c2, start_city, fin_city;
  float d1;
  network<string>::iterator itr; 
  network<string>::iterator moves[50];
  list< string >::iterator list_itr;
  int move_weight[50];
  int move_it, move_temp = 0;
  
  cout << endl << "In the input line, please enter the start and finish cities, separated by a blank.  Each city name should have no blanks and at most 14 characters in length." << endl;
  cin >> start_city >> fin_city;
  cities.insert_vertex(start_city);
  cities.insert_vertex(fin_city);

  while(c1 != "***" && c2 != "***")
  {
    cout << "In the input line, please enter two cities and their distance; the sentinel is ***" << endl;
    cin >> c1;
    if(c1 == "***") break;
    cin >> c2;
    if(c2 == "***") break;
    cin >> d1;
  
    if(!cities.contains_vertex(c1))
      cities.insert_vertex(c1);
    if(!cities.contains_vertex(c2))
      cities.insert_vertex(c2);
    if(!cities.contains_edge(c1, c2))
      cities.insert_edge(c1, c2, d1);
  }

  //output initial state
  outputNetwork(cities);
  
  cities.do_path(cities, start_city, fin_city);
  return 0; 
}


