mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
Added thread test
This commit is contained in:
@@ -8,15 +8,24 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class MCTSAI3 extends MCTSAI {
|
||||
private static final int THREADS = 8;
|
||||
|
||||
private static final ExecutorService threadPool = Executors.newFixedThreadPool(THREADS);
|
||||
private final int threads;
|
||||
private final ExecutorService threadPool;
|
||||
|
||||
public MCTSAI3(int milliseconds) {
|
||||
threads = 8;
|
||||
threadPool = Executors.newFixedThreadPool(8);
|
||||
super(milliseconds);
|
||||
}
|
||||
|
||||
public MCTSAI3(int milliseconds, int threads) {
|
||||
this.threads = 8;
|
||||
threadPool = Executors.newFixedThreadPool(threads);
|
||||
super(milliseconds);
|
||||
}
|
||||
|
||||
public MCTSAI3(MCTSAI3 other) {
|
||||
threads = 8;
|
||||
threadPool = Executors.newFixedThreadPool(8);
|
||||
super(other);
|
||||
}
|
||||
|
||||
@@ -31,7 +40,7 @@ public class MCTSAI3 extends MCTSAI {
|
||||
|
||||
final long endTime = System.nanoTime() + milliseconds * 1_000_000L;
|
||||
|
||||
for (int i = 0; i < THREADS; i++) {
|
||||
for (int i = 0; i < threads; i++) {
|
||||
threadPool.submit(() -> iterate(root, endTime));
|
||||
}
|
||||
|
||||
|
||||
@@ -8,21 +8,29 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class MCTSAI4 extends MCTSAI {
|
||||
private static final int THREADS = 8;
|
||||
|
||||
private static final ExecutorService threadPool = Executors.newFixedThreadPool(THREADS);
|
||||
private final int threads;
|
||||
private final ExecutorService threadPool;
|
||||
|
||||
private Node root;
|
||||
|
||||
public MCTSAI4(int milliseconds) {
|
||||
threads = 8;
|
||||
threadPool = Executors.newFixedThreadPool(8);
|
||||
super(milliseconds);
|
||||
this.root = null;
|
||||
}
|
||||
|
||||
public MCTSAI4(int milliseconds, int threads) {
|
||||
this.threads = threads;
|
||||
threadPool = Executors.newFixedThreadPool(threads);
|
||||
super(milliseconds);
|
||||
this.root = null;
|
||||
}
|
||||
|
||||
public MCTSAI4(MCTSAI4 other) {
|
||||
threads = 8;
|
||||
threadPool = Executors.newFixedThreadPool(8);
|
||||
super(other);
|
||||
|
||||
this.root = other.root;
|
||||
}
|
||||
|
||||
@@ -37,7 +45,7 @@ public class MCTSAI4 extends MCTSAI {
|
||||
|
||||
final long endTime = System.nanoTime() + milliseconds * 1_000_000L;
|
||||
|
||||
for (int i = 0; i < THREADS; i++) {
|
||||
for (int i = 0; i < threads; i++) {
|
||||
threadPool.submit(() -> iterate(root, endTime));
|
||||
}
|
||||
|
||||
|
||||
@@ -23,27 +23,46 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.text.DecimalFormat;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class AITest {
|
||||
|
||||
private static String fileName = "gameDataThreads.csv";
|
||||
|
||||
private static List<Matchup> matchupList = new ArrayList<Matchup>();
|
||||
private static List<AIData> dataList = new ArrayList<AIData>();
|
||||
private static List<GameData> gameDataList = new ArrayList<GameData>();
|
||||
|
||||
// @BeforeAll
|
||||
// public static void init() {
|
||||
//
|
||||
// var versions = new ArtificialPlayer[4];
|
||||
// versions[0] = new ArtificialPlayer(new MCTSAI1(10), "MCTS V1");
|
||||
// versions[1] = new ArtificialPlayer(new MCTSAI2(10), "MCTS V2");
|
||||
// versions[2] = new ArtificialPlayer(new MCTSAI3(10), "MCTS V3");
|
||||
// versions[3] = new ArtificialPlayer(new MCTSAI4(10), "MCTS V4");
|
||||
//
|
||||
// for (int i = 0; i < versions.length; i++) {
|
||||
// for (int j = i + 1; j < versions.length; j++) {
|
||||
// final int playerIndex1 = i % versions.length;
|
||||
// final int playerIndex2 = j % versions.length;
|
||||
// addMatch(versions[playerIndex1], versions[playerIndex2]);
|
||||
// addMatch(versions[playerIndex2], versions[playerIndex1]); // home vs away system
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
@BeforeAll
|
||||
public static void init() {
|
||||
|
||||
var versions = new ArtificialPlayer[4];
|
||||
versions[0] = new ArtificialPlayer(new MCTSAI1(10), "MCTS V1");
|
||||
versions[1] = new ArtificialPlayer(new MCTSAI2(10), "MCTS V2");
|
||||
versions[2] = new ArtificialPlayer(new MCTSAI3(10), "MCTS V3");
|
||||
versions[3] = new ArtificialPlayer(new MCTSAI4(10), "MCTS V4");
|
||||
versions[0] = new ArtificialPlayer(new MCTSAI3(10, 4), "MCTS V3T4");
|
||||
versions[1] = new ArtificialPlayer(new MCTSAI3(10, 8), "MCTS V3T8");
|
||||
versions[2] = new ArtificialPlayer(new MCTSAI3(10, 16), "MCTS V3T16");
|
||||
versions[3] = new ArtificialPlayer(new MCTSAI3(10, 32), "MCTS V3T32");
|
||||
|
||||
for (int i = 0; i < versions.length; i++) {
|
||||
for (int j = i + 1; j < versions.length; j++) {
|
||||
@@ -129,7 +148,7 @@ public class AITest {
|
||||
var ai220 = iterationsAI2.subList(10, 19);
|
||||
var ai230 = iterationsAI2.subList(20, iterationsAI2.size());
|
||||
|
||||
writeGamesToCSV("gameData.csv", new GameData(
|
||||
writeGamesToCSV(fileName, new GameData(
|
||||
AI1,
|
||||
AI2,
|
||||
getWinnerForMatch(AI1, AI2, match),
|
||||
|
||||
Reference in New Issue
Block a user