/** 
 * @author anaaktge
 * @note has extra flag for my hypothesis of random networks 
 * You should fill in the stub for this code file.  The
 * arguments will be given to you 
 */

import java.io.*;
import java.util.*;


public class ProbModelDriver {

	/**
	 * The first argument is the model filename
	 * The second argument should be the value of p, as an ASCII string
	 * The third argument should be the NodeID of the initial product user
	 */
	public static void main(String[] args) {
		if(args.length < 3)
		{
			System.out.println("Usage: ProbModelDriver netDefFilename pValue initialNode (-test) (rand) ");
			return;
		}
		
		String networkFilename = args[0];
		double successProb = Double.parseDouble(args[1]);
		int    startNode = Integer.parseInt(args[2]);
		
		// Put any code here that you need to initialize your network model
		
		// invoke constructor 

		// if a all nodes get a random p 
		if(args.length == 4 && (args[3].toLowerCase().equals("-rand")))
		{
			// create storage lists ofr each answer
			// loop for numSim
			// invoke network create for random prob here
			int size = 10000;
			int[] statAdopted = new int[size]	;
			int[] statGeodesic = new int[size];

			for(int i=0; i<size; i++)
			{
				probControlNetwork randSimNetwork = new
				probControlNetwork(startNode, false,((double)0.0), networkFilename);
			ArrayList results = randSimNetwork.runSimulation();
			//System.out.println("rand aum adopted = "+ results.get(0));
			//System.out.println("rand longest shortest path from maven  = "+ results.get(1));

			statAdopted[i] =((Integer)results.get(0)).intValue();
			statGeodesic[i]=((Integer)results.get(1)).intValue();
		
			}

			// add spilt results into storage lists
			// output to term, w/commas so can go to matlab
			System.out.println("--Rand Assign--");
			System.out.println("---vector of adopted");
			System.out.println(makeArrayStr(statAdopted));
			System.out.println("---vector of dist to maven");
			System.out.println(makeArrayStr(statGeodesic));

			return;
		}
		
		// DO NOT REMOVE THE FOLLOWING CODE.
		if(args.length == 4 && args[3].toLowerCase().equals("-test"))
		{
			// invoke network create for same p
			// create storage lists ofr each answer
			// loop for numSim
			// invoke network create for random prob here


			int size = 10000;
			int[] statAdopted = new int[size] ;
			int[] statGeodesic = new int[size];

			for(int i = 0; i < size; i++)
			{
			probControlNetwork SimNetwork = new probControlNetwork(startNode,true, successProb , networkFilename);
			ArrayList results = new ArrayList(2);
			results = SimNetwork.runSimulation();
			//System.out.println("Num adopted = "+ results.get(0));
			//System.out.println("longest shortest path from maven  = "+ results.get(1));

			statAdopted[i] =((Integer)results.get(0)).intValue();
			statGeodesic[i]=((Integer)results.get(1)).intValue();
			 }
		            
		    // add spilt results into storage lists
		    // output to term, w/commas so can go to matlab
		    System.out.println("--Rand Assign--");
			System.out.println("---vector of adopted");
			System.out.println(makeArrayStr(statAdopted));
			System.out.println("---vectorof dist to maven");
			System.out.println(makeArrayStr(statGeodesic));
																	        

			// add spilt results into storage lists
			// output to term, w/commas so can go to matlab


			//System.out.println("Put your output as specified in the assignment here.");
			return; // make sure that this return is called!
		}
		
		// You are free to do whatever you want here...
		// Bren suggests that you create some helper classes
		// to do the simulation and then run your simulations
		// on a variety of parameters in this space.
		System.out.println("This assignment rocks.");
	}


	public static String makeArrayStr(int[] thisArray)
	{
		String ret = " ";
		for(int i =0; i< thisArray.length; i++)
		{
			ret = ret + ", " + thisArray[i];
		}

		return ret;
	}
}

