Ejemplo n.º 1
0
 /*! Change the domain of a CPF
  * \param cpf -	the original cpf
  * \param bad -	the bad node
  * \param domNew - the new domain
  * \param map - the mapping for keeping from the old domain to the old domain
  * \return the new CPF with the domain rearrangement/change
  */
 public static CPF changeDomain(CPF cpf, BeliefNode bad, Domain domNew, int[] map) {
   Domain Old = bad.getDomain();
   bad.setDomain(domNew);
   BeliefNode[] prod = cpf.getDomainProduct();
   CPF newCPF = new CPF(prod);
   int idx = -1;
   for (int i = 0; i < prod.length; i++) {
     if (prod[i] == bad) idx = i;
   }
   bad.setDomain(Old);
   int[] q = cpf.realaddr2addr(0);
   for (int i = 0; i < cpf.size(); i++) {
     Value v = cpf.get(i);
     int dQ = q[idx];
     if (map[dQ] >= 0) {
       q[idx] = map[dQ];
       bad.setDomain(domNew);
       newCPF.put(q, v);
       bad.setDomain(Old);
       q[idx] = dQ;
     }
     cpf.addOne(q);
   }
   bad.setDomain(Old);
   return newCPF;
 }