Skip to content

Commit

Permalink
Got rid fo Constants class
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Jan 7, 2024
1 parent b7eb809 commit adccfef
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 25 deletions.
19 changes: 0 additions & 19 deletions src/main/java/de/nqueensfaf/Constants.java

This file was deleted.

9 changes: 6 additions & 3 deletions src/main/java/de/nqueensfaf/impl/CPUSolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.esotericsoftware.kryo.io.Output;

import de.nqueensfaf.Config;
import de.nqueensfaf.Constants;
import de.nqueensfaf.Solver;
import de.nqueensfaf.persistence.SolverState;

Expand All @@ -28,6 +27,12 @@ public class CPUSolver extends Solver {
// method for such n
// smallestN marks the border, when to use this simpler solver
private static final int smallestN = 6;
private static final Kryo kryo = new Kryo();
static {
kryo.register(SolverState.class);
kryo.register(Constellation.class);
kryo.register(ArrayList.class);
}

private long start, end;
private ArrayList<Constellation> constellations;
Expand Down Expand Up @@ -116,7 +121,6 @@ protected void save_(String filepath) throws IOException {
if (constellations.size() == 0) {
throw new IllegalStateException("Nothing to be saved");
}
Kryo kryo = Constants.kryo;
try (Output output = new Output(new GZIPOutputStream(new FileOutputStream(filepath)))) {
kryo.writeObject(output,
new SolverState(n, System.currentTimeMillis() - start + storedDuration, constellations));
Expand All @@ -129,7 +133,6 @@ protected void load_(String filepath) throws IOException, ClassNotFoundException
if (!isIdle()) {
throw new IllegalStateException("Cannot load a state while the Solver is running");
}
Kryo kryo = Constants.kryo;
try (Input input = new Input(new GZIPInputStream(new FileInputStream(filepath)))) {
SolverState state = kryo.readObject(input, SolverState.class);
setN(state.getN());
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/de/nqueensfaf/impl/GPUSolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@
import static org.lwjgl.system.MemoryUtil.*;

import de.nqueensfaf.Config;
import de.nqueensfaf.Constants;
import de.nqueensfaf.Solver;
import de.nqueensfaf.SolverException;
import de.nqueensfaf.persistence.SolverState;

public class GPUSolver extends Solver {

private static final Kryo kryo = new Kryo();
static {
kryo.register(SolverState.class);
kryo.register(Constellation.class);
kryo.register(ArrayList.class);
}

private long[] contexts, programs;
private ArrayList<Device> devices, availableDevices;
private ArrayList<Constellation> constellations;
Expand Down Expand Up @@ -469,7 +475,6 @@ protected void save_(String filepath) throws IOException {
throw new IllegalStateException("nothing to be saved");
}

Kryo kryo = Constants.kryo;
try (Output output = new Output(new GZIPOutputStream(new FileOutputStream(filepath)))) {
kryo.writeObject(output,
new SolverState(n, System.currentTimeMillis() - start + storedDuration, constellations));
Expand All @@ -482,7 +487,6 @@ protected void load_(String filepath) throws IOException, ClassNotFoundException
if (!isIdle()) {
throw new IllegalStateException("Cannot load a state while the solver is running");
}
Kryo kryo = Constants.kryo;
try (Input input = new Input(new GZIPInputStream(new FileInputStream(filepath)))) {
SolverState state = kryo.readObject(input, SolverState.class);
setN(state.getN());
Expand Down

0 comments on commit adccfef

Please sign in to comment.