added time optimizations
This commit is contained in:
parent
e4742d8a14
commit
8839c351b9
3 changed files with 29 additions and 2 deletions
|
@ -1,11 +1,12 @@
|
||||||
// Antoine CRETUAL, Lukian LEIZOUR, 14/02/2024
|
// Antoine CRETUAL, Lukian LEIZOUR, 14/02/2024
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
public class AppLaser {
|
public class AppLaser {
|
||||||
public static void main(String [] args) {
|
public static void main(String [] args) {
|
||||||
|
|
||||||
boolean cli = false;
|
boolean cli = false, optimize_duration = false;
|
||||||
|
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
switch (args[i]) {
|
switch (args[i]) {
|
||||||
|
@ -13,6 +14,10 @@ public class AppLaser {
|
||||||
cli = true;
|
cli = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "--optimize-duration":
|
||||||
|
optimize_duration = true;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
System.out.println("Unknown argument " + args[i]);
|
System.out.println("Unknown argument " + args[i]);
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
|
@ -159,6 +164,8 @@ public class AppLaser {
|
||||||
|
|
||||||
universe.print(2, 4);
|
universe.print(2, 4);
|
||||||
|
|
||||||
|
int start_time = (int) Instant.now().getEpochSecond();
|
||||||
|
|
||||||
while (!universe.isSolved()) {
|
while (!universe.isSolved()) {
|
||||||
if (universe.canEvolve(currentState)) {
|
if (universe.canEvolve(currentState)) {
|
||||||
stack.push(currentState.copy(universe.possibleChoices(currentState)));
|
stack.push(currentState.copy(universe.possibleChoices(currentState)));
|
||||||
|
@ -174,11 +181,21 @@ public class AppLaser {
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((int) Instant.now().getEpochSecond() - start_time > 60 && optimize_duration == true) {
|
||||||
|
display_progress = false;
|
||||||
|
}
|
||||||
|
if ((int) Instant.now().getEpochSecond() - start_time > 2 * 60 && optimize_duration == true) {
|
||||||
|
display_regress = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("\n\n");
|
System.out.println("\n\n");
|
||||||
|
|
||||||
universe.print(universe_height + 6, 4);
|
universe.print(universe_height + 6, 4);
|
||||||
|
|
||||||
|
System.out.println("\nSolved in " + ((int) Instant.now().getEpochSecond() - start_time) + " secconds");
|
||||||
|
|
||||||
System.out.print("\033[?25h");
|
System.out.print("\033[?25h");
|
||||||
System.out.print("\nEnter anything to continue....");
|
System.out.print("\nEnter anything to continue....");
|
||||||
scanner.nextInt();
|
scanner.nextInt();
|
||||||
|
|
|
@ -133,6 +133,16 @@ public class Universe {
|
||||||
this.grid = newgrid;
|
this.grid = newgrid;
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
|
|
||||||
|
this.boxes_to_fill = 0;
|
||||||
|
|
||||||
|
for (int i = 1; i < height - 1; i++) {
|
||||||
|
for (int j = 1; j < width - 1; j++) {
|
||||||
|
if (this.grid[i][j] == 0) {
|
||||||
|
this.boxes_to_fill ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeUniverseStart(int pos_i, int pos_j, int dir) {
|
public void changeUniverseStart(int pos_i, int pos_j, int dir) {
|
||||||
|
|
2
makefile
2
makefile
|
@ -4,4 +4,4 @@ build:
|
||||||
|
|
||||||
run:
|
run:
|
||||||
javac --source 1.8 --target 1.8 AppLaser.java
|
javac --source 1.8 --target 1.8 AppLaser.java
|
||||||
java AppLaser -cli
|
java AppLaser -cli --optimize-duration
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue