2 * Copyright (C) 2017 The SyPet Authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package edu.utexas.sypet.synthesis.sat4j;
18 import java.util.ArrayList;
19 import java.util.List;
21 public class Constraint {
23 public static enum ConstraintType {
27 public static enum EncodingType {
28 INIT, GOAL, ONE_TRANSACTION, FIRE_TRANSACTION, FRAME_AXIOMS
32 * Members of Encoding class
34 protected List<Variable> literals;
35 protected List<Integer> coefficients;
36 protected ConstraintType type;
37 protected Integer rhs;
38 protected EncodingType enctype;
43 public Constraint(List<Variable> literals, List<Integer> coefficients, ConstraintType type, Integer rhs){
44 for(Variable v : literals) {
47 this.literals = literals;
48 this.coefficients = coefficients;
53 public Constraint(List<Variable> literals, List<Integer> coefficients, ConstraintType type, Integer rhs, EncodingType enctype){
54 for(Variable v : literals) {
57 this.literals = literals;
58 this.coefficients = coefficients;
61 this.enctype = enctype;
65 public Constraint(List<Variable> literals, ConstraintType type, Integer rhs){
66 for(Variable v : literals) {
69 this.literals = literals;
72 coefficients = new ArrayList<Integer>();
73 for (int i = 0; i < literals.size(); i++)
79 public Constraint(List<Variable> literals, ConstraintType type, Integer rhs, EncodingType enctype){
80 for(Variable v : literals) {
83 this.literals = literals;
85 this.enctype = enctype;
87 coefficients = new ArrayList<Integer>();
88 for (int i = 0; i < literals.size(); i++)
95 this.literals = new ArrayList<Variable>();
96 this.coefficients = new ArrayList<Integer>();
97 this.type = ConstraintType.GEQ;
104 public void addLiteral(Variable v, int coeff){
106 coefficients.add(coeff);
109 public List<Variable> getLiterals(){
113 public List<Integer> getCoefficients(){
117 public ConstraintType getType(){
125 public void setRhs(int rhs){
129 public void setType(ConstraintType type){
133 public int getSize(){
134 return literals.size();
137 public EncodingType getEncodingType(){
142 assert (literals.size() == coefficients.size());
144 for (Variable v : literals){
145 System.out.print(coefficients.get(pos) + " x" + (v.getSolverId()+1) + " [" + v.toString() + "] ");
148 if(type == ConstraintType.EQ)
149 System.out.print("=");
150 else if (type == ConstraintType.GEQ)
151 System.out.print(">=");
152 else if (type == ConstraintType.LEQ)
153 System.out.print("<=");
155 System.out.println(" " + rhs);