Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import de.unisiegen.informatik.bs.alvis.graph.datatypes.*;
- import de.unisiegen.informatik.bs.alvis.primitive.datatypes.*;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import java.util.HashMap;
- import java.util.concurrent.locks.Lock;
- import de.unisiegen.informatik.bs.alvis.vm.*;
- public class Algorithm implements AbstractAlgo {
- private int localbp;
- private Lock lock;
- private boolean onBreak;
- private boolean stopThread = false;
- private boolean onDecision;
- private BPListener bplisten;
- private DPListener dplisten;
- private PCGraph G;
- private PCVertex s;
- public Algorithm() {}
- public void setParameters(Map<String, PCObject> params) {
- this.G = (PCGraph)params.get("G");
- this.s = (PCVertex)params.get("s");
- }
- public Map<String, PCObject> getParameterTypes() {
- Map<String, PCObject> result = new HashMap<String, PCObject>();
- result.put("G", PCGraph.getNull());
- result.put("s", PCVertex.getNull());
- return result;
- }
- public void run() {
- System.out.println("start succ");
- try {
- reachedBreakPoint(0);
- stop();
- {
- for (PCVertex v : (PCList<PCVertex>)reachedDecisionPoint(2, G, G.getVertices())) {
- stop();
- {
- v.setColor(new PCString("white"));
- v.setDistance(PCInteger.getInfty());
- v.setParentId(PCVertex.getNull());
- }
- }
- s.setColor(new PCString("grey"));
- reachedBreakPoint(7);
- stop();
- s.setDistance(new PCInteger(0));
- PCQueue<PCVertex> Q = new PCQueue<PCVertex>();
- Q.enqueue(s);
- while ((Q.isEmpty().not()).getLiteralValue()) {
- stop();
- {
- PCVertex u = new PCVertex();
- u = Q.dequeue();
- for (PCVertex v : (PCList<PCVertex>)reachedDecisionPoint(14, u, u.getAdjacents())) {
- stop();
- if ((v.getColor().equal(new PCString("white"))).getLiteralValue())
- {
- v.setColor(new PCString("grey"));
- reachedBreakPoint(16);
- stop();
- v.setDistance(u.getDistance().add(new PCInteger(1)));
- v.setParentId(u);
- Q.enqueue(v);
- }
- }
- }
- }
- }
- } catch (KillThreadException e) {
- System.out.println("killed now");
- return;
- }
- }
- public static void print(Object o) {
- System.out.println(o);
- }
- /**
- * static code
- *
- * @param BPNr
- * set breakpoint field, inform breakpoint listener, sleeps
- * current thread
- */
- private SortableCollection reachedDecisionPoint(int DPNr,PCObject from ,SortableCollection toSort) {
- if(toSort.size() <= 1) {
- return toSort;
- }
- dplisten.onDecisionPoint(DPNr, from, toSort);
- return toSort;
- }
- /**
- * static code
- *
- * @param BPNr
- * set breakpoint field, inform breakpoint listener, sleeps
- * current thread
- */
- private void reachedBreakPoint(int BPNr) {
- System.out.println("reached bp");
- localbp = BPNr;
- Thread thr = new Thread(new Runnable() {
- public void run() {
- if (bplisten != null) {
- bplisten.onBreakPoint(localbp);
- }
- }
- });
- System.out.println("reached messenger");
- thr.start();
- synchronized (this) {
- onBreak = true;
- do {
- try {
- System.out.println("reached wait in bp");
- wait();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- } while(onBreak);
- System.out.println("leave wait in bp");
- }
- }
- public List<PCObject> getVariableReferences() {
- return null;
- }
- @Override
- public void addBPListener(BPListener wantToListen) {
- bplisten = wantToListen;
- }
- public void addDPListener(DPListener wantToListen) {
- dplisten = wantToListen;
- }
- public void kill() {
- System.out.println("to kill");
- stopThread = true;
- bplisten = null;
- stopBreak();
- System.out.println("to kill done");
- }
- @Override
- public void stopBreak() {
- System.out.println("notify stop bp");
- synchronized (this) {
- onBreak = false;
- this.notify();
- }
- System.out.println("done notify stop bp");
- }
- @Override
- public void setLock(Lock toLockOn) {
- lock = toLockOn;
- }
- private void stop() throws KillThreadException {
- if (stopThread)
- throw new KillThreadException();
- }
- }
Add Comment
Please, Sign In to add comment