Skip to content

Commit

Permalink
Judge Code
Browse files Browse the repository at this point in the history
  • Loading branch information
LinJinghua committed May 25, 2018
1 parent 89c58c3 commit 5b2d7dd
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 16 deletions.
13 changes: 13 additions & 0 deletions README.md
Expand Up @@ -80,6 +80,19 @@ Score:0
```


##### Run
See `test.sh`.

#### Judge

##### Input
```
score
runtime
11
22 1 2 3 4 5 6 7 8 9 10 11 13 17 14 15 21 16 12 19 20 22 0 18 23 24
25 23 10 21 14 17 5 4 11 3 20 2 15 6 1 9 24 7 13 22 18 8 16 12 19 0
25 3 20 6 24 19 22 23 18 10 13 5 2 15 14 4 11 8 21 9 12 1 17 16 7 0
25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
```
Binary file modified lib/jigsaw.jar
Binary file not shown.
64 changes: 48 additions & 16 deletions src/judge/main.java
Expand Up @@ -24,17 +24,23 @@
* @author se-2018
*/
public class main {
private final static long NANOSECOND_PER_MICROSECOND = 1000000L;

private final static int ASTAR_UPPER_LIMIT = 29000;
private final static int ASTAR_LOWER_LIMIT = 1000;
private final static long ASTAR_LOWER_LIMIT_TIME = 15;
private final static int ASTAR_TEST_TIME = 3;

private final static int BFS_SCORE = 2;
private final static int ASTAR_SCORE = 5;
private final static int ASTAR_SCORE = 12;
private final static int ASTAR_MAX_SCORE = 14;

private final static JigsawNode DEST_NODE = new JigsawNode(new int[]{25,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,0});
private static int bfsLength;
private static JigsawNode bfsNode;
private static JigsawNode[] aStarNodes = new JigsawNode[ASTAR_TEST_TIME];


private static JigsawNode getJigsawNode(Scanner scan) {
int len = JigsawNode.getDimension() * JigsawNode.getDimension();
int[] state = new int[len + 1];
Expand All @@ -51,29 +57,50 @@ public static int calBFSScore(int length) {
return 0;
}

public static int calAStarScore(double searchedNodesNum) {
public static int calAStarScore(int rawScore) {
if (rawScore > ASTAR_MAX_SCORE * 2) {
return ASTAR_MAX_SCORE;
}
if (rawScore >= ASTAR_MAX_SCORE) {
return rawScore % ASTAR_MAX_SCORE
+ rawScore / ASTAR_MAX_SCORE * (ASTAR_SCORE / ASTAR_TEST_TIME);
}
return rawScore;
}

public static int estimateAStarScore(int searchedNodesNum, long runTime) {
if (searchedNodesNum < ASTAR_LOWER_LIMIT && runTime <= ASTAR_LOWER_LIMIT_TIME) {
return ASTAR_MAX_SCORE;
}
if (searchedNodesNum < ASTAR_UPPER_LIMIT) {
return ASTAR_SCORE;
return ASTAR_SCORE / ASTAR_TEST_TIME;
}
return 0;
}


public static int TestBFS() {
public static int TestBFS(String runtimeToken) {
JigsawNode destNode = DEST_NODE;
JigsawNode startNode = bfsNode;

Jigsaw solution = new Solution();
boolean solved = false;

try {
if (!solution.BFSearch(new JigsawNode(startNode), new JigsawNode(destNode))) {
return 0;
}
final long startTime = System.nanoTime();

solved = solution.BFSearch(new JigsawNode(startNode), new JigsawNode(destNode));

final long duration = System.nanoTime() - startTime;
System.out.println("\nBFS Total " + runtimeToken + ":" + duration / NANOSECOND_PER_MICROSECOND + "ms");
} catch (Throwable th) {
th.printStackTrace();
return 0;
System.exit(0);
}

if (!solved) {
return 0;
}
List<JigsawNode> solutionPath = solution.getPath();
if (!Jigsaw.isValidPath(solutionPath, startNode, destNode)) {
return 0;
Expand All @@ -84,18 +111,23 @@ public static int TestBFS() {

public static int TestAStar(String runtimeToken) {
long totalTime = 0;
double searchedNodesNum = 0;
int rawScore = 0;

for (int i = 0; i < ASTAR_TEST_TIME; i++) {
final long startTime = System.nanoTime();
searchedNodesNum += TestAStar(aStarNodes[i], DEST_NODE);

int searchedNodesNum = TestAStar(aStarNodes[i], DEST_NODE);

final long duration = System.nanoTime() - startTime;
System.out.println("\nAStar " + runtimeToken + ":" + duration / NANOSECOND_PER_MICROSECOND + "ms");
totalTime += duration;
System.out.println("\n" + runtimeToken + ":" + duration / 1000000 + "ms");

rawScore += estimateAStarScore(searchedNodesNum, duration / NANOSECOND_PER_MICROSECOND);
}
System.out.println("\nTotal " + runtimeToken + ":" + totalTime / 1000000 + "ms");
System.out.println("Average " + runtimeToken + ":" + totalTime / 1000000 / ASTAR_TEST_TIME + "ms");

return calAStarScore(searchedNodesNum / ASTAR_TEST_TIME);
System.out.println("\nAStar Total " + runtimeToken + ":" + totalTime / NANOSECOND_PER_MICROSECOND + "ms");

return calAStarScore(rawScore);
}

public static int TestAStar(JigsawNode startNode, JigsawNode destNode) {
Expand All @@ -107,7 +139,7 @@ public static int TestAStar(JigsawNode startNode, JigsawNode destNode) {
}
} catch (Throwable th) {
th.printStackTrace();
return Integer.MAX_VALUE;
System.exit(0);
}

List<JigsawNode> solutionPath = solution.getPath();
Expand All @@ -133,6 +165,6 @@ public static void main(String[] args) {
aStarNodes[i] = getJigsawNode(scan);
}

System.out.println("\n" + scoreToken + ":" + (TestBFS() + TestAStar(runtimeToken)));
System.out.println("\n" + scoreToken + ":" + (TestBFS(runtimeToken) + TestAStar(runtimeToken)));
}
}

0 comments on commit 5b2d7dd

Please sign in to comment.