import choco.Problem; import choco.mem.StoredInt; import choco.mem.StoredLong; import choco.mem.Environment; // // public class RList { private StoredInt length; // the length of the list private StoredLong tot; // the total/sum of the list private RElement start; // an element with next pointing to start of list private RElement[] elem; // elements of the list private Environment e; // whatever that is private int n; // initial length of list private StoredInt[][] adj; // adjacency matrix, to get solution private int[] partition; // the partition of a number: 0=left, 1=right public RList(Problem pb,long[] N) { n = N.length; e = pb.getEnvironment(); length = new StoredInt(e,n); tot = new StoredLong(e,0); start = new RElement(e,-1,0,0); elem = new RElement[n + 1]; adj = new StoredInt[n][n]; partition = new int[n]; for (int i=0;i x.getData()){ w = y; y = elem[y.getNext()]; } x.setNext(y.getLocn()); w.setNext(x.getLocn()); } // // insert element x into the list in order // public void sum(){ RElement x = first(); RElement y = second(); y.setData(x.getData() + y.getData()); x.setData(-1); start.setNext(y.getLocn()); length.set(length.get() - 1); adj[x.getLocn()][y.getLocn()].set(+1); // set an edge that states sum/same partition adj[y.getLocn()][x.getLocn()].set(+1); } // // add the 1st and second elements of the list // removing the 1st element // public void diff(){ RElement x = first(); RElement y = second(); tot.set(tot.get() - 2*y.getData()); x.setData(x.getData() - y.getData()); y.setData(-1); start.setNext(y.getNext()); insert(x); length.set(length.get() - 1); adj[x.getLocn()][y.getLocn()].set(-1); // set an edge that states diff/different partition adj[y.getLocn()][x.getLocn()].set(-1); } private void dfs(int i){ for (int j=0;j