import java.io.*; import java.util.*; import java.util.Arrays; import java.util.Collections; import org.chocosolver.solver.*; import org.chocosolver.solver.variables.*; import org.chocosolver.solver.constraints.*; import org.chocosolver.solver.search.strategy.*; public class MWCCP { int n; // number of vertices int[] weight; // vertex weights Solver solver; // a solver object, to attach variables and constraints int[][] adjacent; // adjacent[i][j] = 1 <-> vertices are adjacent int[] degree; // vertex degree; IntVar[] vertex; // vertex[i] = 1 <-> ith vertex selected String id; // an identification for the problem IntVar totalWeight; // sum of weights of selected vertices int minWeight; // minimum vertex weight int maxWeight; // maximum vertex weight String order; // increasing ("incWeight" or "incDegree") or decreasing ("decWeight" or decDegree") public MWCCP(String fname,String order) throws Exception { Scanner sc = new Scanner(new File(fname)); id = fname; solver = new Solver(id); n = sc.nextInt(); minWeight = sc.nextInt(); maxWeight = sc.nextInt(); weight = new int[n]; adjacent = new int[n][n]; degree = new int[n]; vertex = VF.enumeratedArray("vertex",n,0,1,solver); totalWeight = VF.enumerated("totalWeight",minWeight,maxWeight*n,solver); // dumb this.order = order; // read vertex weights for (int i=0;i0;i--) for (int j=0;j sortedWeight[j+1])) swap(j,j+1,sortedWeight,sortedVertex); else if ((order.equals("decDegree") && sortedDegree[j] < sortedDegree[j+1]) || (order.equals("incDegree") && sortedDegree[j] > sortedDegree[j+1])) swap(j,j+1,sortedDegree,sortedVertex); return sortedVertex; } public void optimize(){ solver.set(ISF.lexico_UB(getDecisionVars(order))); solver.findOptimalSolution(ResolutionPolicy.MAXIMIZE,totalWeight); } public static void main(String[] args) throws FileNotFoundException, IOException, Exception { String order = "none"; if (args.length == 2) order = args[1]; MWCCP mwc = new MWCCP(args[0],order); mwc.optimize(); Solver solver = mwc.solver; System.out.print(mwc.totalWeight.getValue() + " "); System.out.print(solver.getMeasures().getNodeCount() + " "); System.out.println((int)(solver.getMeasures().getTimeCount() * 1000)); for (int i=0;i