Skip to content

Commit

Permalink
github issue #31
Browse files Browse the repository at this point in the history
  • Loading branch information
radsz committed Nov 16, 2020
1 parent 47e8f62 commit 4ae59c0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 32 deletions.
10 changes: 10 additions & 0 deletions src/main/java/org/jacop/constraints/ExtensionalConflictVA.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public class ExtensionalConflictVA extends Constraint implements UsesQueueVariab

public IntVar[] list;

private boolean satisfiedAlreadyAtImposition = false;

/**
* Partial constructor which stores variables involved in a constraint but
* does not get information about tuples yet. The tuples must set separately.
Expand Down Expand Up @@ -360,6 +362,10 @@ public int seekInvalidPosition(int[] t) {
if (debugAll)
System.out.println("Begin " + this);

if (satisfiedAlreadyAtImposition) {
return;
}

boolean pruned = true;

while (pruned) {
Expand Down Expand Up @@ -615,6 +621,10 @@ protected int findPosition(int value, int[] values) {

}

if (tuplesFromConstructor.length == 0) {
satisfiedAlreadyAtImposition = true;
}

tuplesFromConstructor = null;

store.raiseLevelBeforeConsistency = true;
Expand Down
56 changes: 56 additions & 0 deletions src/test/java/org/jacop/ConstraintStatusKnownAtImposition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.jacop;

import org.jacop.constraints.ExtensionalConflictVA;
import org.jacop.constraints.knapsack.Knapsack;
import org.jacop.core.IntVar;
import org.jacop.core.Store;
import org.junit.Test;

public class ConstraintStatusKnownAtImposition {

@Test
public void testSimpleFailSetupAtImpositionKnapsack() {

Store store = new Store();

IntVar v0 = new IntVar(store, "v0", 1, 1);
IntVar v1 = new IntVar(store, "v1", 0, 0);
IntVar v2 = new IntVar(store, "v2", 1, 1);
IntVar v3 = new IntVar(store, "v3", 0, 0);
IntVar v4 = new IntVar(store, "v4", 0, 0);

Knapsack cons = new Knapsack(
new int[]{1, 2, 3},
new int[]{1, 2, 3},
new IntVar[]{v1, v2, v3},
v4,
v0);

store.impose(cons);

}

@Test
public void testSimpleAlreadySatisfiedSetupAtImpositionConflictVA() {
Store store = new Store ();

IntVar v1 = new IntVar (store, "v1", 0, 0);
IntVar v2 = new IntVar (store, "v2", 1, 1);

ExtensionalConflictVA cons = new ExtensionalConflictVA (
new IntVar[] { v1, v2 },
new int[][] {
new int[] {0, 0}, new int[] {1, 1}
}
);

store.impose(cons);

System.out.println(cons);
System.out.println(store);

store.consistency();
}


}
32 changes: 0 additions & 32 deletions src/test/java/org/jacop/KnapsackTest.java

This file was deleted.

0 comments on commit 4ae59c0

Please sign in to comment.