Skip to content

Commit

Permalink
[PExplicit] Refactoring and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aman-goel committed Apr 30, 2024
1 parent 6ac0535 commit a71d77e
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public static PExplicitConfig ParseCommandlineArgs(String[] args) {
config.setSearchStrategyMode(SearchStrategyMode.Random);
break;
case "astar":
config.setSearchStrategyMode (SearchStrategyMode.AStar);
config.setSearchStrategyMode(SearchStrategyMode.AStar);
break;
default:
optionError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import pexplicit.commandline.PExplicitConfig;
import pexplicit.runtime.machine.PMachine;
import pexplicit.runtime.scheduler.Scheduler;
import pexplicit.runtime.scheduler.explicit.strategy.SearchStrategy;
import pexplicit.runtime.scheduler.explicit.strategy.SearchStrategyMode;

import java.util.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,9 @@ private void setChildTask(Choice choice, int choiceNum, SearchTask parentTask, b
searchStrategy.addNewTask(newTask);
}

/** Set next backtrack task with given orchestration mode */
/**
* Set next backtrack task with given orchestration mode
*/
public SearchTask setNextTask() {
SearchTask nextTask = searchStrategy.setNextTask();
if (nextTask != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package pexplicit.runtime.scheduler.explicit.strategy;

import lombok.Getter;
import pexplicit.runtime.PExplicitGlobal;
import pexplicit.runtime.logger.PExplicitLogger;
import pexplicit.runtime.scheduler.Choice;
import pexplicit.runtime.scheduler.explicit.SearchStatistics;

Expand Down Expand Up @@ -42,13 +40,6 @@ public SearchTask createTask(Choice choice, int choiceNum, SearchTask parentTask
return newTask;
}

private void setCurrTask(SearchTask task) {
assert (pendingTasks.contains(task.getId()));
pendingTasks.remove(task.getId());
currTaskId = task.getId();
currTaskStartIteration = SearchStatistics.iteration;
}

public void createFirstTask() {
assert (allTasks.size() == 0);
SearchTask firstTask = createTask(null, 0, null);
Expand All @@ -59,13 +50,18 @@ public SearchTask getCurrTask() {
return getTask(currTaskId);
}

private void setCurrTask(SearchTask task) {
assert (pendingTasks.contains(task.getId()));
pendingTasks.remove(task.getId());
currTaskId = task.getId();
currTaskStartIteration = SearchStatistics.iteration;
}

public int getNumSchedulesInCurrTask() {
return SearchStatistics.iteration - currTaskStartIteration;
}



private boolean isValidTaskId(int id) {
return (id < allTasks.size());
}
Expand Down Expand Up @@ -93,7 +89,7 @@ public SearchTask setNextTask() {
*/
public int getNumPendingChoices() {
int numUnexplored = 0;
for (Integer tid: pendingTasks) {
for (Integer tid : pendingTasks) {
SearchTask task = getTask(tid);
numUnexplored += task.getNumUnexploredScheduleChoices() + task.getNumUnexploredDataChoices();
}
Expand All @@ -107,7 +103,7 @@ public int getNumPendingChoices() {
*/
public int getNumPendingDataChoices() {
int numUnexplored = 0;
for (Integer tid: pendingTasks) {
for (Integer tid : pendingTasks) {
SearchTask task = getTask(tid);
numUnexplored += task.getNumUnexploredDataChoices();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
import java.util.concurrent.PriorityBlockingQueue;

public class SearchStrategyAStar extends SearchStrategy {
private final PriorityBlockingQueue<SearchTask> elements;
private final PriorityBlockingQueue<SearchTask> elements;

public SearchStrategyAStar() {
elements =
new PriorityBlockingQueue<SearchTask>(
100,
new Comparator<SearchTask>() {
public int compare(SearchTask a, SearchTask b) {
return Integer.compare(a.getCurrChoiceNumber(), b.getCurrChoiceNumber());
}
});
}
public SearchStrategyAStar() {
elements =
new PriorityBlockingQueue<SearchTask>(
100,
new Comparator<SearchTask>() {
public int compare(SearchTask a, SearchTask b) {
return Integer.compare(a.getCurrChoiceNumber(), b.getCurrChoiceNumber());
}
});
}

public void addNewTask(SearchTask task) {
elements.offer(task);
}
public void addNewTask(SearchTask task) {
elements.offer(task);
}

public SearchTask popNextTask() {
assert (!elements.isEmpty());
return elements.poll();
}
public SearchTask popNextTask() {
assert (!elements.isEmpty());
return elements.poll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@
import java.util.*;

public class SearchStrategyRandom extends SearchStrategy {
private final List<SearchTask> elementList;
private final Set<SearchTask> elementSet;
private final List<SearchTask> elementList;
private final Set<SearchTask> elementSet;

public SearchStrategyRandom() {
elementList = new ArrayList<>();
elementSet = new HashSet<>();
}
public SearchStrategyRandom() {
elementList = new ArrayList<>();
elementSet = new HashSet<>();
}

public void addNewTask(SearchTask task) {
assert (!elementSet.contains(task));
elementList.add(task);
elementSet.add(task);
}
public void addNewTask(SearchTask task) {
assert (!elementSet.contains(task));
elementList.add(task);
elementSet.add(task);
}

public SearchTask popNextTask() {
assert (!elementList.isEmpty());
Collections.shuffle(
elementList, new Random(RandomNumberGenerator.getInstance().getRandomLong()));
SearchTask result = elementList.get(0);
elementList.remove(0);
elementSet.remove(result);
return result;
}
public SearchTask popNextTask() {
assert (!elementList.isEmpty());
Collections.shuffle(
elementList, new Random(RandomNumberGenerator.getInstance().getRandomLong()));
SearchTask result = elementList.get(0);
elementList.remove(0);
elementSet.remove(result);
return result;
}
}
Loading

0 comments on commit a71d77e

Please sign in to comment.