Advertisement
Guest User

Class Transport

a guest
Feb 10th, 2013
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.37 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package transporte;
  6.  
  7. import ExamplesJaCoP.Example;
  8. import JaCoP.constraints.Sum;
  9. import JaCoP.constraints.SumWeight;
  10. import JaCoP.core.IntVar;
  11. import JaCoP.core.Store;
  12. import JaCoP.core.Var;
  13. import JaCoP.search.DepthFirstSearch;
  14. import JaCoP.search.IndomainMin;
  15. import JaCoP.search.SelectChoicePoint;
  16. import JaCoP.search.SimpleSelect;
  17. import java.util.ArrayList;
  18. import javax.swing.JOptionPane;
  19.  
  20.  
  21. /**
  22.  *
  23.  * @author Carlos
  24.  */
  25. public class Transporte extends Example{
  26.    
  27.     @Override
  28.     public void model(){
  29.    
  30.         store = new Store();
  31.         vars = new ArrayList<>();
  32.         cost = new IntVar();
  33.        
  34.         /** Variables Limitadas por su respectivo rango **/
  35.         IntVar bogota = new IntVar(store, "Bogota", 0, 20);
  36.         IntVar medellin = new IntVar(store, "Medellin", 0, 40);
  37.         IntVar cali = new IntVar(store, "Cali", 0, 40);
  38.        
  39.         /** Bogota **/
  40.         IntVar x13 = new IntVar(store, "X13", 20, 20);// X13 del Origen 1 al destino 3, 20 es la demanda del origen 3
  41.         /** Medellin **/
  42.         IntVar x21 = new IntVar(store, "X21", 25, 25);
  43.         IntVar x22 = new IntVar(store, "X22", 10, 10);
  44.         IntVar x24 = new IntVar(store, "X24", 5,5);
  45.         /** Cali **/
  46.         IntVar x34 = new IntVar(store, "X34", 25, 25);
  47.         IntVar x35 = new IntVar(store, "X35", 15, 15);
  48.        
  49.         /** Bogota **/
  50.         ArrayList<IntVar> b = new ArrayList<>();
  51.         b.add(x13);
  52.         store.impose(new Sum(b, bogota));
  53.        
  54.         /** Medellin **/
  55.        
  56.         ArrayList<IntVar> m = new ArrayList<>();
  57.         m.add(x21);m.add(x22);m.add(x24);
  58.         store.impose(new Sum(m, medellin));
  59.        
  60.         /** Cali **/
  61.         ArrayList<IntVar> c = new ArrayList<>();
  62.         c.add(x34);c.add(x35);
  63.         store.impose(new Sum(c, cali));
  64.        
  65.         IntVar[] rDemanda = {x13,x21,x22,x24,x34,x35}; // se Crea Arreglo para añadirlo a Vars
  66.        
  67.        
  68.        
  69.         /** Operaciones con Variables **/
  70.        
  71.         ArrayList<IntVar> x = new ArrayList<>();
  72.         x.add(x13);x.add(x21);x.add(x22);x.add(x24);x.add(x34); x.add(x35);
  73.         ArrayList<Integer> y = new ArrayList<>();
  74.         y.add(40);y.add(35);y.add(30);y.add(45);y.add(35);y.add(30); // <-- se ingresan los costos como constante
  75.         //store.impose(new Sum(x, cost));
  76.         store.impose(new SumWeight(x,y, cost));
  77.        
  78.         for(Var v: rDemanda)
  79.         {
  80.             vars.add(v);
  81.         }
  82.        
  83.         vars.add(cost);
  84.     }
  85.    
  86.     public static void main(String[] args) {
  87.        
  88.         Transporte example = new Transporte();
  89.         example.model();
  90.        if(example.searchOptimal()){
  91.        
  92.            JOptionPane.showMessageDialog(null," Solucion Encontrada ");
  93.        }
  94.        
  95.        
  96.     }
  97.    
  98.     /**public boolean searchOptimal() {
  99.        
  100.         long T1, T2;
  101.         T1 = System.currentTimeMillis();
  102.        
  103.         SelectChoicePoint select = new SimpleSelect(vars.toArray(new Var[1]), null,
  104.                 new IndomainMin());
  105.  
  106.         search = new DepthFirstSearch();
  107.        
  108.         boolean result = search.labeling(store, select, cost);
  109.  
  110.         if (result)
  111.             store.print();
  112.  
  113.         T2 = System.currentTimeMillis();
  114.  
  115.         System.out.println("\n\t*** Execution time = " + (T2 - T1) + " ms");
  116.        
  117.         return result;
  118.        
  119.     }   */
  120.  
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement