aboutsummaryrefslogtreecommitdiffstats
path: root/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/NumericProblemSolver.java
blob: 8f57e40c7d91ca974d15aa0ed70cf6a42dbb7633 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package hu.bme.mit.inf.dslreasoner.viatra2logic;

import java.util.List;
import java.util.Map;

import org.eclipse.xtext.common.types.JvmIdentifiableElement;
import org.eclipse.xtext.xbase.XExpression;

import com.microsoft.z3.Expr;

import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PrimitiveElement;

public abstract class NumericProblemSolver {
	protected static final String N_Base = "org.eclipse.xtext.xbase.lib.";
	protected static final String N_PLUS = "operator_plus";
	protected static final String N_MINUS = "operator_minus";
	protected static final String N_POWER = "operator_power";
	protected static final String N_MULTIPLY = "operator_multiply";
	protected static final String N_DIVIDE = "operator_divide";
	protected static final String N_MODULO = "operator_modulo";
	protected static final String N_LESSTHAN = "operator_lessThan";
	protected static final String N_LESSEQUALSTHAN = "operator_lessEqualsThan";
	protected static final String N_GREATERTHAN = "operator_greaterThan";
	protected static final String N_GREATEREQUALTHAN = "operator_greaterEqualsThan";
	protected static final String N_EQUALS = "operator_equals";
	protected static final String N_NOTEQUALS = "operator_notEquals";
	protected static final String N_EQUALS3 = "operator_tripleEquals";
	protected static final String N_NOTEQUALS3 = "operator_tripleNotEquals";
	
	protected long endformingProblem=0;
	protected long endSolvingProblem=0;
	protected long endFormingSolution=0;

	public long getEndformingProblem() {return endformingProblem;}
	public long getEndSolvingProblem() {return endSolvingProblem;}
	public long getEndFormingSolution() {return endFormingSolution;}
	
	public boolean isSatisfiable(Map<XExpression, Iterable<Map<JvmIdentifiableElement,PrimitiveElement>>> matches) throws Exception {
		if(!initialized) {
			this.initialize();
			this.initialized=true;
		}
		return this.internalIsSatisfiable(matches);
	}
	public Map<PrimitiveElement,Number> getOneSolution(List<PrimitiveElement> objs, Map<XExpression, Iterable<Map<JvmIdentifiableElement,PrimitiveElement>>> matches) throws Exception{
		if(!initialized) {
			this.initialize();
			this.initialized=true;
		}
		return this.internalGetOneSolution(objs, matches);
	}
	
	boolean initialized = false;
	protected abstract void initialize();
	
	protected abstract boolean internalIsSatisfiable(Map<XExpression, Iterable<Map<JvmIdentifiableElement,PrimitiveElement>>> matches) throws Exception;
	protected abstract Map<PrimitiveElement,Number> internalGetOneSolution(List<PrimitiveElement> objs, Map<XExpression, Iterable<Map<JvmIdentifiableElement,PrimitiveElement>>> matches) throws Exception;
}