Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package transporte;
- import ExamplesJaCoP.Example;
- import JaCoP.constraints.Sum;
- import JaCoP.constraints.SumWeight;
- import JaCoP.core.IntVar;
- import JaCoP.core.Store;
- import JaCoP.core.Var;
- import JaCoP.search.DepthFirstSearch;
- import JaCoP.search.IndomainMin;
- import JaCoP.search.SelectChoicePoint;
- import JaCoP.search.SimpleSelect;
- import java.util.ArrayList;
- import javax.swing.JOptionPane;
- /**
- *
- * @author Carlos
- */
- public class Transporte extends Example{
- @Override
- public void model(){
- store = new Store();
- vars = new ArrayList<>();
- cost = new IntVar();
- /** Variables Limitadas por su respectivo rango **/
- IntVar bogota = new IntVar(store, "Bogota", 0, 20);
- IntVar medellin = new IntVar(store, "Medellin", 0, 40);
- IntVar cali = new IntVar(store, "Cali", 0, 40);
- /** Bogota **/
- IntVar x13 = new IntVar(store, "X13", 20, 20);// X13 del Origen 1 al destino 3, 20 es la demanda del origen 3
- /** Medellin **/
- IntVar x21 = new IntVar(store, "X21", 25, 25);
- IntVar x22 = new IntVar(store, "X22", 10, 10);
- IntVar x24 = new IntVar(store, "X24", 5,5);
- /** Cali **/
- IntVar x34 = new IntVar(store, "X34", 25, 25);
- IntVar x35 = new IntVar(store, "X35", 15, 15);
- /** Bogota **/
- ArrayList<IntVar> b = new ArrayList<>();
- b.add(x13);
- store.impose(new Sum(b, bogota));
- /** Medellin **/
- ArrayList<IntVar> m = new ArrayList<>();
- m.add(x21);m.add(x22);m.add(x24);
- store.impose(new Sum(m, medellin));
- /** Cali **/
- ArrayList<IntVar> c = new ArrayList<>();
- c.add(x34);c.add(x35);
- store.impose(new Sum(c, cali));
- IntVar[] rDemanda = {x13,x21,x22,x24,x34,x35}; // se Crea Arreglo para añadirlo a Vars
- /** Operaciones con Variables **/
- ArrayList<IntVar> x = new ArrayList<>();
- x.add(x13);x.add(x21);x.add(x22);x.add(x24);x.add(x34); x.add(x35);
- ArrayList<Integer> y = new ArrayList<>();
- y.add(40);y.add(35);y.add(30);y.add(45);y.add(35);y.add(30); // <-- se ingresan los costos como constante
- //store.impose(new Sum(x, cost));
- store.impose(new SumWeight(x,y, cost));
- for(Var v: rDemanda)
- {
- vars.add(v);
- }
- vars.add(cost);
- }
- public static void main(String[] args) {
- Transporte example = new Transporte();
- example.model();
- if(example.searchOptimal()){
- JOptionPane.showMessageDialog(null," Solucion Encontrada ");
- }
- }
- /**public boolean searchOptimal() {
- long T1, T2;
- T1 = System.currentTimeMillis();
- SelectChoicePoint select = new SimpleSelect(vars.toArray(new Var[1]), null,
- new IndomainMin());
- search = new DepthFirstSearch();
- boolean result = search.labeling(store, select, cost);
- if (result)
- store.print();
- T2 = System.currentTimeMillis();
- System.out.println("\n\t*** Execution time = " + (T2 - T1) + " ms");
- return result;
- } */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement