////////////////////////////////////////////////////////////////////////////
/*
      High Level Synthesis Homework#1 - Programming Type homework

        Implemented Algorithm :
           < Find the Shortest Path and Longest Path in direct graph >

                                        20023086 Kim SeonPil
                                        Prof. MAREK ANDRZEJ PERKOWSKI

                                                      2002.9.24
                                                                          */
////////////////////////////////////////////////////////////////////////////

//import slp.*;

import java.util.*;
import java.io.*;
import java.text.*;
/////////////////////////////////////////////////////////
/*
    class skpkim ( has no meaing)

    Variablie:
        INFINITE  : to represent the upper boundary

    Functions
        main      : Execution and test function
        read_int(): Function to input the int value
                    return the inputed int value
        read_int_with_parsing():
                    For Input of Edge (head,tail,weight), input with parsing
                                                        */
/////////////////////////////////////////////////////////

public class kspkim
{
  /*Variable Declaration*/
  public static final int INFINITE=1000;

  public static void main(String[] args)
  {

  /* Receive the parameters that set the graph */
  int starting_vertex;
  int exiting_vertex;
  int num_of_vertex;

  int[] return_value = new int[3];  // array to save return value from read_int_with_parsing()

    System.out.println("Enter the number of vertice");
    num_of_vertex = read_int();

    System.out.println("Starting vertex number");
    starting_vertex = read_int();
    System.out.println("Exiting vertex number");
    exiting_vertex = read_int();

  /*initialize graph*/
    graph g = new graph(num_of_vertex);


  /*Put WeightOnEdge and Neighbor Vertex Conditions*/
    System.out.println("Input the Edge condition and weight as the order of head,tail,weight");
    System.out.println("ex) 0,1,3");
     do{
      return_value = read_int_with_parsing();

      if(return_value[0]!=INFINITE)
      {
        g.Put_EdgeToGraph(return_value[0],return_value[1],return_value[2]);   // Edge Setting
      }
      System.out.println("If you want to input edges, Enter Edge Characteristic as the order of head,tail,weight");
      System.out.println("Else you want to stop inputting edges, press Just Enter");

    }while(return_value[0]!=INFINITE);  // Exiting Condition: Input String is Null(Just Enter)

    System.out.println("");

    /* Result Presentation Part */

    System.out.println("/////////////////////////////////////////////");
    System.out.println("                       result                ");
    System.out.println("/////////////////////////////////////////////");

    System.out.println("************************************************");
    g.ShortestPath(starting_vertex,exiting_vertex,num_of_vertex);
    System.out.println("************************************************");

    System.out.println("************************************************");
    g.LongestPath(starting_vertex,exiting_vertex,num_of_vertex);
    System.out.println("************************************************");

    System.out.println("Quit Processing");
  }
/////////////////////////////////////////////////////////
//  Input Function : read_int()
//                    : Function to input the int value
//                      return the inputed int value
//  input : None
//  return: integer
/////////////////////////////////////////////////////////

    public static int read_int()
    {
    int a;
      try{
    InputStreamReader is = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(is);

    String s  = br.readLine();      //read Stream to String form

    /* Translate String format to int format */
    DecimalFormat d = new DecimalFormat();
    Number n = d.parse(s);          // parse to number
    a = n.intValue();            // change form to double form

    }catch(IOException ex)
    {a = 0;}
    catch(ParseException ex)    //Exception cases
    {a = 0;}
    return a;
    }

/////////////////////////////////////////////////////////
//  Input Function : read_int_with_parsing()
//                    : Function to input the int value with parsing by ","
//                      return the inputed integer array
//  input : None
//  return: integer array
/////////////////////////////////////////////////////////

    public static int[] read_int_with_parsing()
    {
    int[] a= new int[3];
    String temp;
    String s = new String();

    for(int i=0;i<3;i++) a[i]=INFINITE;

    try{
    InputStreamReader is = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(is);

    s  = br.readLine();      //read Stream to String form

    if(s.length()==0) return(a);

    /* Parse Inputed String with "," */
    StringTokenizer stk = new StringTokenizer( s,",");
    for( int i =0 ; i < 3&& stk.hasMoreTokens() ; i++ )
    {
    temp = stk.nextToken();

    /* Translate String format to int format */
    DecimalFormat d = new DecimalFormat();
    Number n = d.parse(temp);          // parse to number
    a[i] = n.intValue();            // change form to double form

    }
    }catch(IOException ex)
    {System.out.println("IOExcetion");}
     catch(ParseException ex)
    {System.out.println("ParseExcetion");}  //Exception cases

    return a;     // return array
    }
}

