Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. import JaCoP.core.*;
  2. import JaCoP.constraints.*;
  3. import JaCoP.search.*;
  4. import JaCoP.constraints.binpacking.*;
  5.  
  6. import java.io.*;
  7. /**
  8. * The class Run is used to run test programs for JaCoP package.
  9. * It is used for test purpose only.
  10. *
  11. * @author Krzysztof Kuchcinski
  12. * @version 3.0
  13. */
  14. public class Ex {
  15.  
  16. Store store;
  17. IntVar vars;
  18. IntVar Cost;
  19. int CostValue;
  20. static boolean bbSearch = true;
  21.  
  22. public static void main (String args) {
  23. int position = 0;
  24. if (args.length() >= 1)
  25.  
  26. if (args.equals("-bb")) {
  27. position++;
  28. bbSearch = true;
  29. }
  30.  
  31. else if (args.equals("-restart")) {
  32. position++;
  33. bbSearch = false;
  34. }
  35.  
  36. Ex run = new Ex();
  37.  
  38. run.example();
  39. }
  40.  
  41. // Ex() {}
  42.  
  43. void example() {
  44. store = new Store();
  45. int[] w = {10,10,10,10,9,9,8,9,1,1,1,1,1};
  46. IntVar b[] = new IntVar[15];
  47.  
  48. for (int i = 0; i < w.length; i++) {
  49. b[i] = new IntVar(store, "b"+i, 0, 10);
  50. }
  51.  
  52. int bins = 8;
  53. IntVar c[] = new IntVar[15];
  54.  
  55. for (int i = 0; i < bins; i++) {
  56. c[i] = new IntVar(store, "c"+i, 10, 10);
  57. }
  58.  
  59. Constraint binPacking = new Binpacking(b, c, w);
  60. store.impose( binPacking );
  61. boolean Result = store.consistency();
  62. System.out.println (binPacking);
  63. System.out.println( "\nIntVar store size: "+ store.size()+"\nNumber of constraints: " + store.numberConstraints() );
  64. Search<IntVar> label = new DepthFirstSearch<IntVar>();
  65. SelectChoicePoint<IntVar> select = new SimpleSelect<IntVar>(b, null, new IndomainMin<IntVar>());
  66. label.setAssignSolution(true);
  67. label.setPrintInfo(true);
  68. Result = label.labeling(store, select);
  69.  
  70. if (Result) {
  71. System.out.println("*** Yes");
  72. System.out.println (java.util.Arrays.asList(b));
  73. System.out.println (java.util.Arrays.asList(c));
  74. }
  75.  
  76. else
  77. System.out.println("*** No");
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement