Skip to content
Snippets Groups Projects
Commit cc6ee52b authored by Sebastian Krings's avatar Sebastian Krings
Browse files

add progress bar to model checking dialog

parent 4cecc9b3
Branches
Tags
No related merge requests found
...@@ -12,8 +12,7 @@ import de.prob.core.Animator; ...@@ -12,8 +12,7 @@ import de.prob.core.Animator;
import de.prob.exceptions.ProBException; import de.prob.exceptions.ProBException;
import de.prob.parser.ISimplifiedROMap; import de.prob.parser.ISimplifiedROMap;
import de.prob.prolog.output.IPrologTermOutput; import de.prob.prolog.output.IPrologTermOutput;
import de.prob.prolog.term.CompoundPrologTerm; import de.prob.prolog.term.*;
import de.prob.prolog.term.PrologTerm;
public final class ModelCheckingCommand implements IComposableCommand { public final class ModelCheckingCommand implements IComposableCommand {
private final int time; private final int time;
...@@ -43,8 +42,7 @@ public final class ModelCheckingCommand implements IComposableCommand { ...@@ -43,8 +42,7 @@ public final class ModelCheckingCommand implements IComposableCommand {
public static ModelCheckingResult<Result> modelcheck(final Animator a, public static ModelCheckingResult<Result> modelcheck(final Animator a,
final int time, final List<String> options) throws ProBException { final int time, final List<String> options) throws ProBException {
ModelCheckingCommand command = new ModelCheckingCommand( ModelCheckingCommand command = new ModelCheckingCommand(time, options);
time, options);
a.execute(command); a.execute(command);
return command.getResult(); return command.getResult();
} }
...@@ -53,20 +51,32 @@ public final class ModelCheckingCommand implements IComposableCommand { ...@@ -53,20 +51,32 @@ public final class ModelCheckingCommand implements IComposableCommand {
return result; return result;
} }
@Override
public void processResult( public void processResult(
final ISimplifiedROMap<String, PrologTerm> bindings) final ISimplifiedROMap<String, PrologTerm> bindings)
throws CommandException { throws CommandException {
CompoundPrologTerm term = (CompoundPrologTerm) bindings.get("Result"); CompoundPrologTerm term = (CompoundPrologTerm) bindings.get("Result");
result = new ModelCheckingResult<Result>(Result.class, term);
CompoundPrologTerm stats = (CompoundPrologTerm) bindings.get("Stats");
int processedTotal = ((IntegerPrologTerm) stats.getArgument(3))
.getValue().intValue();
int numStates = ((IntegerPrologTerm) stats.getArgument(1)).getValue()
.intValue();
int workedSoFar = (int) (1000 * Math.pow((double) processedTotal
/ numStates, 5));
result = new ModelCheckingResult<Result>(Result.class, term,
workedSoFar);
} }
@Override
public void writeCommand(final IPrologTermOutput pto) { public void writeCommand(final IPrologTermOutput pto) {
pto.openTerm("do_modelchecking").printNumber(time).openList(); pto.openTerm("do_modelchecking").printNumber(time).openList();
for (String o : options) { for (String o : options) {
pto.printAtom(o); pto.printAtom(o);
} }
pto.closeList().printVariable("Result").closeTerm(); pto.closeList().printVariable("Result");
pto.printVariable("Stats").closeTerm();
} }
} }
...@@ -6,23 +6,23 @@ ...@@ -6,23 +6,23 @@
package de.prob.core.command; package de.prob.core.command;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import de.prob.prolog.term.CompoundPrologTerm; import de.prob.prolog.term.*;
import de.prob.prolog.term.PrologTerm;
public class ModelCheckingResult<T extends Enum<T>> { public class ModelCheckingResult<T extends Enum<T>> {
private final T result; private final T result;
private final List<PrologTerm> arguments = new ArrayList<PrologTerm>(); private final List<PrologTerm> arguments = new ArrayList<PrologTerm>();
private final int worked;
public ModelCheckingResult(final Class<T> enumeration, public ModelCheckingResult(final Class<T> enumeration,
final CompoundPrologTerm term) { final CompoundPrologTerm term, int workDone) {
result = Enum.valueOf(enumeration, term.getFunctor()); result = Enum.valueOf(enumeration, term.getFunctor());
for (int i = 1; i <= term.getArity(); i++) { for (int i = 1; i <= term.getArity(); i++) {
arguments.add(term.getArgument(i)); arguments.add(term.getArgument(i));
} }
worked = workDone;
} }
public PrologTerm getArgument(final int i) { public PrologTerm getArgument(final int i) {
...@@ -33,4 +33,7 @@ public class ModelCheckingResult<T extends Enum<T>> { ...@@ -33,4 +33,7 @@ public class ModelCheckingResult<T extends Enum<T>> {
return result; return result;
} }
public int getWorked() {
return worked;
}
} }
...@@ -6,20 +6,14 @@ ...@@ -6,20 +6,14 @@
package de.prob.ui.eventb; package de.prob.ui.eventb;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Set;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.Job;
import de.prob.core.Animator; import de.prob.core.Animator;
import de.prob.core.command.ModelCheckingCommand; import de.prob.core.command.*;
import de.prob.core.command.ModelCheckingCommand.Result; import de.prob.core.command.ModelCheckingCommand.Result;
import de.prob.core.command.ModelCheckingSearchOption;
import de.prob.core.command.SetPreferenceCommand;
import de.prob.exceptions.ProBException; import de.prob.exceptions.ProBException;
public class ModelCheckingJob extends Job { public class ModelCheckingJob extends Job {
...@@ -28,7 +22,8 @@ public class ModelCheckingJob extends Job { ...@@ -28,7 +22,8 @@ public class ModelCheckingJob extends Job {
private boolean abort = false; private boolean abort = false;
private final List<String> options; private final List<String> options;
private final String symmetryOption; private final String symmetryOption;
private Result modelCheckingResult = null; private ModelCheckingResult<Result> modelCheckingResult = null;
private int workedSoFar = 0;
public ModelCheckingJob(final String name, public ModelCheckingJob(final String name,
final Set<ModelCheckingSearchOption> options, final Set<ModelCheckingSearchOption> options,
...@@ -43,7 +38,7 @@ public class ModelCheckingJob extends Job { ...@@ -43,7 +38,7 @@ public class ModelCheckingJob extends Job {
} }
public Result getModelCheckingResult() { public Result getModelCheckingResult() {
return modelCheckingResult; return modelCheckingResult.getResult();
} }
@Override @Override
...@@ -52,16 +47,21 @@ public class ModelCheckingJob extends Job { ...@@ -52,16 +47,21 @@ public class ModelCheckingJob extends Job {
return Status.CANCEL_STATUS; return Status.CANCEL_STATUS;
} }
monitor.beginTask("Model checking", IProgressMonitor.UNKNOWN); monitor.beginTask("Model checking", 1000);
while (!abort) { while (!abort) {
try { try {
modelCheckingResult = doSomeModelchecking(); modelCheckingResult = doSomeModelchecking();
options.remove("inspect_existing_nodes"); options.remove("inspect_existing_nodes");
monitor.worked(500);
int difference = modelCheckingResult.getWorked() - workedSoFar;
if (difference > 0) {
monitor.worked(difference);
workedSoFar = modelCheckingResult.getWorked();
}
} catch (ProBException e) { } catch (ProBException e) {
return Status.CANCEL_STATUS; // Failed return Status.CANCEL_STATUS; // Failed
} }
abort = modelCheckingResult.isAbort() || monitor.isCanceled(); abort = getModelCheckingResult().isAbort() || monitor.isCanceled();
} }
return Status.OK_STATUS; return Status.OK_STATUS;
} }
...@@ -76,9 +76,9 @@ public class ModelCheckingJob extends Job { ...@@ -76,9 +76,9 @@ public class ModelCheckingJob extends Job {
return true; return true;
} }
private Result doSomeModelchecking() throws ProBException { private ModelCheckingResult<Result> doSomeModelchecking()
return ModelCheckingCommand.modelcheck(animator, 500, options) throws ProBException {
.getResult(); return ModelCheckingCommand.modelcheck(animator, 500, options);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment