Skip to content

Commit

Permalink
Always try to dump pruning files at first start
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregor Billing committed Jan 8, 2020
1 parent 9afeb81 commit 7107b64
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
11 changes: 7 additions & 4 deletions threephase/src/main/java/cs/threephase/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,23 @@ private static void read(int[][] arr, DataInput in) throws IOException {
for (int j=0, len=arr[i].length; j<len; j++) {
arr[i][j] = in.readInt();
}
}
}
}

private static void write(int[][] arr, DataOutput out) throws IOException {
for (int i=0, leng=arr.length; i<leng; i++) {
for (int j=0, len=arr[i].length; j<len; j++) {
out.writeInt(arr[i][j]);
}
}
}
}

public synchronized static void initFrom(DataInput in) throws IOException {
if (Search.inited) {
return;
}

System.out.println("Loading pruning tables from file...");
System.out.println("Initialize Center1 Solver...");

Center1.initSym();
Expand All @@ -58,7 +59,7 @@ public synchronized static void initFrom(DataInput in) throws IOException {
Edge3.initRaw2Sym();
read(Edge3.eprun, in);

System.out.println("OK");
System.out.println("OK");

Search.inited = true;
}
Expand All @@ -67,7 +68,9 @@ public synchronized static void saveTo(DataOutput out) throws IOException {
if (!Search.inited) {
Search.init();
}
System.out.println("Writing pruning tables to file...");

write(Center1.ctsmv, out);
write(Edge3.eprun, out);
}
}
}
2 changes: 2 additions & 0 deletions webscrambles/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ dependencies {
implementation(project(":scrambles"))
implementation(project(":server-ktor"))

implementation(project(":threephase"))

implementation(ZIP4J)
implementation(ITEXTPDF)
implementation(BATIK_TRANSCODER)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.worldcubeassociation.tnoodle.server.webscrambles

import com.xenomachina.argparser.ArgParser
import cs.threephase.Tools
import io.ktor.application.Application
import io.ktor.routing.routing
import io.ktor.server.engine.commandLineEnvironment
Expand All @@ -23,6 +24,8 @@ import org.worldcubeassociation.tnoodle.server.webscrambles.routing.*
import org.worldcubeassociation.tnoodle.server.webscrambles.server.LocalServerEnvironmentConfig
import org.worldcubeassociation.tnoodle.server.webscrambles.server.MainLauncher
import org.worldcubeassociation.tnoodle.server.webscrambles.server.OfflineJarUtils
import java.io.DataInputStream
import java.io.DataOutputStream

class WebscramblesServer(val environmentConfig: ServerEnvironmentConfig) : ApplicationHandler {
private val baseServer = TNoodleServer(environmentConfig)
Expand All @@ -36,6 +39,16 @@ class WebscramblesServer(val environmentConfig: ServerEnvironmentConfig) : Appli
val scrambleHandler = ScrambleHandler(environmentConfig)
val scrambleViewHandler = ScrambleViewHandler(environmentConfig)

if (environmentConfig.pruningTableExists(THREEPHASE_PRUNING)) {
DataInputStream(environmentConfig.getPruningTableInput(THREEPHASE_PRUNING)).use {
Tools.initFrom(it)
}
} else {
DataOutputStream(environmentConfig.getPruningTableOutput(THREEPHASE_PRUNING)).use {
Tools.saveTo(it)
}
}

app.routing {
PuzzleListHandler.install(this)
RouteRedirectHandler.install(this)
Expand All @@ -52,6 +65,8 @@ class WebscramblesServer(val environmentConfig: ServerEnvironmentConfig) : Appli
companion object {
const val MIN_HEAP_SIZE_MEGS = 512

const val THREEPHASE_PRUNING = "444-threephase"

val LOG = LoggerFactory.getLogger(WebscramblesServer::class.java)

fun spinUpLocally(app: Application) =
Expand Down

0 comments on commit 7107b64

Please sign in to comment.