public double get_h_value(Vertex t) {
    ArrayList<Vertex> chems = G.getChemV();
    double ans = 0;
    double t_dis = (this.d).get_t_dis_in_dList(d_list, t.getIndex());

    int v_c_index;
    int v_index;
    double v_dis;
    double dis;

    for (int i = 0; i < chems.size(); i++) {
      // get the index of the vertex in chem ver
      v_c_index = (chems.get(i)).getIndex();
      // get the index of him in d_list
      v_index = (this.d).getIndexInList(this.d_list, v_c_index);
      // get his distance
      v_dis = ((this.d_list).get(v_index)).get_dis();
      // compute the distance between t and chems.get(i):
      dis = Math.abs(t_dis - v_dis);
      // inc the ans
      ans = ans + dis;
    }

    return ans * 2;
  }
 public double h() {
   double val = 0;
   Iterator<diikstra_ver> it = d_list.iterator();
   while (it.hasNext()) {
     diikstra_ver v = it.next();
     if (G.getVertex(v.get_index() - 1).hasChems()) {
       val += v.get_dis();
     }
   }
   return val;
 }
  public double get_f_value(Double H_value) {
    double ans = 0;

    ArrayList<Vertex> chems = G.getChemV();

    int v_c_index;
    int v_index;
    double v_dis;

    for (int i = 0; i < chems.size(); i++) {
      // get the index of the vertex in chem ver
      v_c_index = (chems.get(i)).getIndex();
      // get the index of him in d_list
      v_index = (this.d).getIndexInList(this.d_list, v_c_index);
      // get his distance
      v_dis = ((this.d_list).get(v_index)).get_dis();
      // we already know that d[s] = 0
      // therefore we only accumulate the d[v]
      ans = ans + v_dis;
    }
    return ans;
  }
Ejemplo n.º 4
0
 public RobotPuzzle(Graph g, int x, int y, int gx, int gy) {
   graph = g;
   location = g.getNode(x, y);
   goal = g.getNode(gx, gy);
   System.out.println();
 }