Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help adding h 1 time and h 2 time ( the time it takes for each heuristic ) . this is another class
I need help adding h time and h time the time it takes for each heuristic this is another class i have:
public class OutputData used to store the solution depth and search cost of a given puzzle solution for printing
public int solutionDepth;
public int searchCost;
public OutputDataint solutionDepth, int searchCost
this.solutionDepth solutionDepth;
this.searchCost searchCost;
this is my main class: public class Main
static Scanner sc new ScannerSystemin;
static AStarSearch search new AStarSearch;
public static void mainString args
boolean validInput false;
String prompt "Select:
Generate Random Puzzle
Enter Puzzle
Exit
validChoices ;
int choice ;
whilevalidInput
System.out.printlnprompt;
System.out.printEnter choice: ;
choice getChoice;
ifvalidChoicescontainsStringvalueOfchoicecheck if input is
validInput true;
Main test new Main;
switch choiceuser enter puzzle or generate random puzzle based on user choice
case :
test.randomPuzzle;
break;
case :
test.userPuzzle;
break;
case :
System.out.printlnGoodbye;
scclose;
System.exit;
break;
default:
break;
public void randomPuzzle
Map completeData new TreeMap; treemap for storing data of multiple cases
int testCases ;
do
System.out.printHow many random puzzles would you like to solve? ;
testCases getChoice; get amount of random puzzles to generate
while testCases ;
forint i ; i testCases; i
Puzzle randomPuzzle new Puzzle; generate random puzzle
OutputData solution solverandomPuzzle; pass random puzzle into solve method to get corresponding data
ifcompleteData.containsKeysolutiondepthmake new entry in data set if depth of random puzzle does not exist in the set
completeData.putsolutiondepth, new ArrayList;
completeData.getsolutiondepthaddsolution; add data to the specified depth
System.out.printfDepth Total Cases Manhattan Search Cost Manhattan Elapsed Time Misplaced Search Cost Misplaced Elapsed Time";
completeData.entrySetstreamforEachentry
int hAverage hAvgTime hAverage hAvgTime total entry.getValuesize;
forint i ; i entry.getValuesize; i
OutputData data entry.getValuegeti;
hAverage data.searchCostH;
hAvgTime data.totalTimeH;
hAverage data.searchCostH;
hAvgTime data.totalTimeH;
System.out.println;
System.out.printfd d d d ms d d ms entry.getKey total, hAverage totalhAvgTimetotalhAveragetotalhAvgTimetotal;
;
public void userPuzzle
boolean puzzleCreated false;
String puzzleString;
Integer temp ;
Puzzle userPuzzle new Puzzletemp;
whilepuzzleCreated
puzzleString getPuzzle;
puzzleCreated userPuzzle.createPuzzlepuzzleString;
search.aStaruserPuzzlepuzzle, "manhattan";
search.aStaruserPuzzlepuzzle, "misplaced";
public static int getChoice
int choice ;
try
choice Integer.parseIntscnextLine;
catch Exception e
System.out.printlnEnter an integer.";
return choice;
public static String getPuzzle
String puzzleString ;
int rows ;
System.out.printlnEnter puzzle: ;
forint i ; i rows; i
System.out.printfRow d: i ;
puzzleString scnextLinereplace; make the strin
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started