Skip to content

Commit 7d852d0

Browse files
committed
Merge branch 'development'
2 parents 73359fd + 189e682 commit 7d852d0

File tree

19 files changed

+432
-48
lines changed

19 files changed

+432
-48
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![wercker status](https://app.wercker.com/status/24c4765f3a0d79520ad80a1e4c20cfa2/s/master "wercker status")](https://app.wercker.com/project/bykey/24c4765f3a0d79520ad80a1e4c20cfa2) [![Coverage Status](https://coveralls.io/repos/logic-ng/LogicNG/badge.svg?branch=master&service=github)](https://coveralls.io/github/logic-ng/LogicNG?branch=master) ![License](https://img.shields.io/badge/license-Apache%202-blue.svg) ![Version](https://img.shields.io/badge/version-1.6.0-ff69b4.svg)
1+
[![wercker status](https://app.wercker.com/status/24c4765f3a0d79520ad80a1e4c20cfa2/s/master "wercker status")](https://app.wercker.com/project/bykey/24c4765f3a0d79520ad80a1e4c20cfa2) [![Coverage Status](https://coveralls.io/repos/logic-ng/LogicNG/badge.svg?branch=master&service=github)](https://coveralls.io/github/logic-ng/LogicNG?branch=master) ![License](https://img.shields.io/badge/license-Apache%202-blue.svg) ![Version](https://img.shields.io/badge/version-1.6.1-ff69b4.svg)
22

33
<img src="https://github.com/logic-ng/LogicNG/blob/master/doc/logo/logo_big.png" alt="logo" width="300">
44

@@ -19,7 +19,7 @@ LogicNG is released in the Maven Central Repository. To include it just add
1919
<dependency>
2020
<groupId>org.logicng</groupId>
2121
<artifactId>logicng</artifactId>
22-
<version>1.6.0</version>
22+
<version>1.6.1</version>
2323
</dependency>
2424
```
2525
to your Maven POM.
@@ -62,6 +62,10 @@ We recently started a Wiki section for a [FAQ](https://github.com/logic-ng/Logic
6262
The library is released under the Apache License and therefore is free to use in any private, educational, or commercial projects. Commercial support is available through the German company [BooleWorks GmbH](http://www.booleworks.com) - the company behind LogicNG. Please contact Christoph Zengler at christoph@logicng.org for further details.
6363

6464
## Changelog
65+
### Version 1.6.1 (Release September 2019)
66+
* A new method for solving a formula with a given literal ordering.
67+
* Minor refactoring of the Formatter super class (no effects on callers).
68+
* Fixed the behaviour of model enumeration with additional variables.
6569

6670
### Version 1.6.0 (Release September 2019)
6771
* A new method for generating CNFs directly on the solver instead of using the formula factory.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<modelVersion>4.0.0</modelVersion>
2727
<groupId>org.logicng</groupId>
2828
<artifactId>logicng</artifactId>
29-
<version>1.6.0</version>
29+
<version>1.6.1</version>
3030
<packaging>jar</packaging>
3131

3232
<name>LogicNG</name>

src/main/java/org/logicng/explanations/unsatcores/algorithms/PlainInsertionBasedMUS.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public <T extends Proposition> UNSATCore<T> computeMUS(List<T> propositions, For
5959
solver.add(p);
6060
int count = currentFormula.size();
6161
while (solver.sat() == Tristate.TRUE) {
62-
if (count < 0)
62+
if (count == 0)
6363
throw new IllegalArgumentException("Cannot compute a MUS for a satisfiable formula set.");
6464
final T removeProposition = currentFormula.get(--count);
6565
currentSubset.add(removeProposition);

src/main/java/org/logicng/formulas/printer/FormulaStringRepresentation.java

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,31 @@
3232

3333
/**
3434
* Super class for a formula string representation.
35-
*
3635
* @version 1.3
3736
* @since 1.0
3837
*/
3938
public abstract class FormulaStringRepresentation {
4039

4140
/**
4241
* Returns the string representation of the given formula.
43-
*
42+
* <p>
43+
* In order to add a prefix/suffix or do one-time calculations on the formula it is recommended to overwrite this
44+
* method in sub-classes.
4445
* @param formula the formula
4546
* @return the string representation of the formula
4647
*/
4748
public String toString(final Formula formula) {
49+
return toInnerString(formula);
50+
}
51+
52+
/**
53+
* Returns the string representation of the given formula.
54+
* <p>
55+
* This method is used for recursive calls in order to format the sub-formulas.
56+
* @param formula the formula
57+
* @return the string representation of the formula
58+
*/
59+
protected String toInnerString(Formula formula) {
4860
switch (formula.type()) {
4961
case FALSE:
5062
return this.falsum();
@@ -68,10 +80,11 @@ public String toString(final Formula formula) {
6880
return this.naryOperator(nary, String.format("%s", op));
6981
case PBC:
7082
final PBConstraint pbc = (PBConstraint) formula;
71-
if (pbc.isTrivialFalse())
83+
if (pbc.isTrivialFalse()) {
7284
return this.falsum();
73-
else if (pbc.isTrivialTrue())
85+
} else if (pbc.isTrivialTrue()) {
7486
return this.verum();
87+
}
7588
return String.format("%s%s%d", this.pbLhs(pbc.operands(), pbc.coefficients()), this.pbComparator(pbc.comparator()), pbc.rhs());
7689
default:
7790
throw new IllegalArgumentException("Cannot print the unknown formula type " + formula.type());
@@ -80,32 +93,29 @@ else if (pbc.isTrivialTrue())
8093

8194
/**
8295
* Returns a bracketed string version of a given formula.
83-
*
8496
* @param formula the formula
8597
* @return {@code "(" + formula.toString() + ")"}
8698
*/
8799
protected String bracket(final Formula formula) {
88-
return String.format("%s%s%s", this.lbr(), this.toString(formula), this.rbr());
100+
return String.format("%s%s%s", this.lbr(), this.toInnerString(formula), this.rbr());
89101
}
90102

91103
/**
92104
* Returns the string representation of a binary operator.
93-
*
94105
* @param operator the binary operator
95106
* @param opString the operator string
96107
* @return the string representation
97108
*/
98109
protected String binaryOperator(final BinaryOperator operator, final String opString) {
99110
final String leftString = operator.type().precedence() < operator.left().type().precedence()
100-
? this.toString(operator.left()) : this.bracket(operator.left());
111+
? this.toInnerString(operator.left()) : this.bracket(operator.left());
101112
final String rightString = operator.type().precedence() < operator.right().type().precedence()
102-
? this.toString(operator.right()) : this.bracket(operator.right());
113+
? this.toInnerString(operator.right()) : this.bracket(operator.right());
103114
return String.format("%s%s%s", leftString, opString, rightString);
104115
}
105116

106117
/**
107118
* Returns the string representation of an n-ary operator.
108-
*
109119
* @param operator the n-ary operator
110120
* @param opString the operator string
111121
* @return the string representation
@@ -119,19 +129,18 @@ protected String naryOperator(final NAryOperator operator, final String opString
119129
if (++count == size) {
120130
last = op;
121131
} else {
122-
sb.append(operator.type().precedence() < op.type().precedence() ? this.toString(op) : this.bracket(op));
132+
sb.append(operator.type().precedence() < op.type().precedence() ? this.toInnerString(op) : this.bracket(op));
123133
sb.append(opString);
124134
}
125135
}
126136
if (last != null) {
127-
sb.append(operator.type().precedence() < last.type().precedence() ? this.toString(last) : this.bracket(last));
137+
sb.append(operator.type().precedence() < last.type().precedence() ? this.toInnerString(last) : this.bracket(last));
128138
}
129139
return sb.toString();
130140
}
131141

132142
/**
133143
* Returns the string representation of the left-hand side of a pseudo-Boolean constraint.
134-
*
135144
* @param operands the literals of the constraint
136145
* @param coefficients the coefficients of the constraint
137146
* @return the string representation
@@ -160,85 +169,73 @@ protected String pbLhs(final Literal[] operands, final int[] coefficients) {
160169

161170
/**
162171
* Returns the string representation of false.
163-
*
164172
* @return the string representation of false
165173
*/
166174
protected abstract String falsum();
167175

168176
/**
169177
* Returns the string representation of true.
170-
*
171178
* @return the string representation of true
172179
*/
173180
protected abstract String verum();
174181

175182
/**
176183
* Returns the string representation of not.
177-
*
178184
* @return the string representation of not
179185
*/
180186
protected abstract String negation();
181187

182188
/**
183189
* Returns the string representation of an implication.
184-
*
185190
* @return the string representation of an implication
186191
*/
187192
protected abstract String implication();
188193

189194
/**
190195
* Returns the string representation of an equivalence.
191-
*
192196
* @return the string representation of an equivalence
193197
*/
194198
protected abstract String equivalence();
195199

196200
/**
197201
* Returns the string representation of and.
198-
*
199202
* @return the string representation of and
200203
*/
201204
protected abstract String and();
202205

203206
/**
204207
* Returns the string representation of or.
205-
*
206208
* @return the string representation of or
207209
*/
208210
protected abstract String or();
209211

210212
/**
211213
* Returns the string representation of a pseudo-Boolean comparator.
212-
*
213214
* @param comparator the pseudo-Boolean comparator
214215
* @return the string representation of a pseudo-Boolean comparator
215216
*/
216217
protected abstract String pbComparator(final CType comparator);
217218

218219
/**
219220
* Returns the string representation of a pseudo-Boolean multiplication.
220-
*
221221
* @return the string representation of a pseudo-Boolean multiplication
222222
*/
223223
protected abstract String pbMul();
224224

225225
/**
226226
* Returns the string representation of a pseudo-Boolean addition.
227-
*
228227
* @return the string representation of a pseudo-Boolean addition
229228
*/
230229
protected abstract String pbAdd();
231230

232231
/**
233232
* Returns the string representation of a left bracket.
234-
*
235233
* @return the string representation of a left bracket
236234
*/
237235
protected abstract String lbr();
238236

239237
/**
240238
* Returns the string representation of right bracket.
241-
*
242239
* @return the string representation of right bracket
243240
*/
244241
protected abstract String rbr();

src/main/java/org/logicng/formulas/printer/LatexStringRepresentation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ private static String latexName(final String name) {
5959
}
6060

6161
@Override
62-
public String toString(final Formula formula) {
62+
public String toInnerString(final Formula formula) {
6363
switch (formula.type()) {
6464
case LITERAL:
6565
final Literal lit = (Literal) formula;
6666
return lit.phase() ? latexName(lit.name()) : this.negation() + " " + latexName(lit.name());
6767
default:
68-
return super.toString(formula);
68+
return super.toInnerString(formula);
6969
}
7070
}
7171

src/main/java/org/logicng/formulas/printer/SortedStringRepresentation.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public SortedStringRepresentation(final List<Variable> varOrder) {
9999
* @return the sorted string representation of the formula with regard to the variable ordering
100100
*/
101101
@Override
102-
public String toString(final Formula formula) {
102+
public String toInnerString(final Formula formula) {
103103
switch (formula.type()) {
104104
case FALSE:
105105
return falsum();
@@ -154,12 +154,12 @@ protected String naryOperator(final NAryOperator operator, final String opString
154154
if (++count == size) {
155155
last = op;
156156
} else {
157-
sb.append(operator.type().precedence() < op.type().precedence() ? toString(op) : bracket(op));
157+
sb.append(operator.type().precedence() < op.type().precedence() ? toInnerString(op) : bracket(op));
158158
sb.append(opString);
159159
}
160160
}
161161
if (last != null) {
162-
sb.append(operator.type().precedence() < last.type().precedence() ? toString(last) : bracket(last));
162+
sb.append(operator.type().precedence() < last.type().precedence() ? toInnerString(last) : bracket(last));
163163
}
164164
return sb.toString();
165165
}
@@ -226,8 +226,8 @@ private String sortedEquivalence(final Equivalence equivalence) {
226226
right = equivalence.left();
227227
left = equivalence.right();
228228
}
229-
final String leftString = FType.EQUIV.precedence() < left.type().precedence() ? toString(left) : bracket(left);
230-
final String rightString = FType.EQUIV.precedence() < right.type().precedence() ? toString(right) : bracket(right);
229+
final String leftString = FType.EQUIV.precedence() < left.type().precedence() ? toInnerString(left) : bracket(left);
230+
final String rightString = FType.EQUIV.precedence() < right.type().precedence() ? toInnerString(right) : bracket(right);
231231
return String.format("%s%s%s", leftString, equivalence(), rightString);
232232
}
233233

src/main/java/org/logicng/formulas/printer/UTF8StringRepresentation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ private static String getSubscript(final String number) {
9999
}
100100

101101
@Override
102-
public String toString(final Formula formula) {
102+
protected String toInnerString(final Formula formula) {
103103
switch (formula.type()) {
104104
case LITERAL:
105105
final Literal lit = (Literal) formula;
106106
return lit.phase() ? utf8Name(lit.name()) : this.negation() + utf8Name(lit.name());
107107
default:
108-
return super.toString(formula);
108+
return super.toInnerString(formula);
109109
}
110110
}
111111

src/main/java/org/logicng/solvers/CleaneLing.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,4 +426,14 @@ public SortedSet<Literal> upZeroLiterals() {
426426
public Set<Formula> formulaOnSolver() {
427427
throw new UnsupportedOperationException("The CleaneLing solver does not support returning the formula on the solver");
428428
}
429+
430+
@Override
431+
public void setSelectionOrder(List<? extends Literal> selectionOrder) {
432+
throw new UnsupportedOperationException("The CleaneLing solver does not support a custom selection order");
433+
}
434+
435+
@Override
436+
public void resetSelectionOrder() {
437+
throw new UnsupportedOperationException("The CleaneLing solver does not support a custom selection order");
438+
}
429439
}

src/main/java/org/logicng/solvers/MiniSat.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@
7878
import java.util.SortedSet;
7979
import java.util.TreeSet;
8080

81-
import static org.logicng.datastructures.Tristate.FALSE;
82-
import static org.logicng.datastructures.Tristate.TRUE;
83-
import static org.logicng.datastructures.Tristate.UNDEF;
84-
8581
/**
8682
* Wrapper for the MiniSAT-style SAT solvers.
8783
* @version 1.6.0
@@ -378,15 +374,19 @@ public List<Assignment> enumerateAllModels(final Collection<Variable> variables,
378374
}
379375
}
380376
LNGIntVector relevantAllIndices = null;
377+
final TreeSet<Variable> uniqueAdditionalVariables = new TreeSet<>(additionalVariables);
378+
if (variables != null) {
379+
uniqueAdditionalVariables.removeAll(variables);
380+
}
381381
if (relevantIndices != null) {
382-
if (additionalVariables.isEmpty()) {
382+
if (uniqueAdditionalVariables.isEmpty()) {
383383
relevantAllIndices = relevantIndices;
384384
} else {
385-
relevantAllIndices = new LNGIntVector(relevantIndices.size() + additionalVariables.size());
385+
relevantAllIndices = new LNGIntVector(relevantIndices.size() + uniqueAdditionalVariables.size());
386386
for (int i = 0; i < relevantIndices.size(); ++i) {
387387
relevantAllIndices.push(relevantIndices.get(i));
388388
}
389-
for (final Variable var : additionalVariables) {
389+
for (final Variable var : uniqueAdditionalVariables) {
390390
relevantAllIndices.push(this.solver.idxForName(var.name()));
391391
}
392392
}
@@ -709,4 +709,14 @@ public Set<Formula> formulaOnSolver() {
709709
}
710710
return formulas;
711711
}
712+
713+
@Override
714+
public void setSelectionOrder(final List<? extends Literal> selectionOrder) {
715+
this.solver.setSelectionOrder(selectionOrder);
716+
}
717+
718+
@Override
719+
public void resetSelectionOrder() {
720+
this.solver.resetSelectionOrder();
721+
}
712722
}

0 commit comments

Comments
 (0)