2017-05-14 4 views
2

Wenn zwei Kacheln tj und tk in einem linearen Konflikt sind, wenn tj und tk in derselben Zeile sind, sind die Zielpositionen von tj und tk beide in dieser Zeile, tj ist rechts von tk und Zielposition von tj ist links von der Zielposition von tk.Lineare Konflikte, die Zulässigkeit verletzen und mich verrückt machen

Der lineare Konflikt fügt der Manhattan-Distanz der beiden in Konflikt stehenden Kacheln mindestens zwei Züge hinzu, indem sie gezwungen werden, sich gegenseitig zu umgeben. Daher fügt die heuristische Funktion für jedes Paar in Konflikt stehender Kacheln Kosten von 2 Zügen hinzu. Die Linar-Konfliktheuristik ist zulässig, aber der Algorithmus, den ich verwende, verletzt manchmal die Zulässigkeit, was bedeutet, dass er pessimistisch ist und nicht unbedingt eine optimale Position findet.

Hier

ist der Code:

private int linearVerticalConflict(State s) { 
    int state[] = s.getState(); 
    int dimension = (int) Math.sqrt(state.length); 
    int linearConflict = 0; 
    int count = 0; 
    for (int row = 0; row < dimension; row++) { 
     int max = -1; 
     for (int column = 0; column < dimension; column++) { 
      int cellValue = state[count]; 
      count++; 
      //int cellValue = newState[row][column]; 
      //is tile in its goal row ? 
      if (cellValue != 0 && (cellValue - 1)/dimension == row) { 
       if (cellValue > max) { 
        max = cellValue; 
       } else { 
        //linear conflict, one tile must move up or down to 
        // allow the other to pass by and then back up 
        //add two moves to the manhattan distance 
        linearConflict += 2; 
       } 
      } 

     } 

    } 
    return linearConflict; 
} 

private int linearHorizontalConflict(State s) { 
    int[] state = s.getState(); 
    int dimension = (int) Math.sqrt(state.length); 
    int linearConflict = 0; 
    int count = 0; 
    for (int column = 0; column < dimension; column++) { 
     int max = -1; 
     for (int row = 0; row < dimension; row++) { 
      int cellValue = state[count]; 
      count++; 
      //is tile in its goal row ? 
      if (cellValue != 0 && cellValue % dimension == column + 1) { 
       if (cellValue > max) { 
        max = cellValue; 
       } else { 
        //linear conflict, one tile must move left or right to allow the other to pass by and then back up 
        //add two moves to the manhattan distance 
        linearConflict += 2; 
       } 
      } 

     } 

    } 
    return linearConflict; 
} 

Der Algorithmus verletzt Zulässigkeit wenn: sagen, wir sind auf einer Reihe konzentrieren, die die Konfiguration [3, 1, 2]

Nehmen wir an, [1 , 2, 3] ist die Zielkonfiguration.

Die summierte Manhattan Entfernung für das Problem ist: 4 (3 Züge 2 mal, 1 Züge 1 Zeit und 2 Züge 1 Mal) Der lineare Konflikt für die Reihe ist: 4 (1 und 2 sind beide weniger als 3 so + 2 + 2)

, die in einer Gesamt heuristische Schätzung von 8. Ergebnisse [3, 1, 2] kann in 6 bewegt gelöst werden,

Antwort

3

Die lineare Konflikt heuristische komplizierter ist als nur das Hinzufügen 2 für jedes Paar widersprüchlicher Kacheln.

Die Heuristik ist beschrieben in "Criticizing Solutions to Relaxed Models Yields Powerful Admissible Heuristics" by OTHAR HANSSON and ANDREW MAYER and MOTI YUNG in INFORMATION SCIENCES 63, 207-227 (1992)

Der Algorithmus in Abbildung 5 beschrieben wird, und beinhaltet das Berechnen der minimalen Anzahl von zusätzlichen verschiebt alle Konflikte in einer Reihe zu lösen. Wie Sie herausgefunden haben, ist dies nicht gleich der doppelten Anzahl von Konfliktpaaren.

Der Algorithmus präsentierte eigentlich ist:

Begin {Algorithm LC} 
{ s is the current state} 
{ L is the size of a line (row or column) in the puzzle. L = sqrt(N + 1) 
{ C(tj, ri) is the number of tiles in row ri with which tj is in conflict} 
{ C(tj, ci) similarly} 
{ lc(s, rj) is the number of tiles that must be removed from row rj to resolve the linear conflicts} 
{ lc(s, cj) similarly} 
{ md(s, ti) is the Manhattan Distance of tile ti} 
{ MD(s) is the sum of the Manhattan Distances of all the tiles in s} 
{ LC(s) is the minimum number of additional moves needed to resolve the linear conflicts in s} 
For each row ri in the state s 
    lc(s, ri) = 0 
    For each tile tj in ri 
     determine C(tj, ri) 
    While there is a non-zero C(tj, ri) value 
     Find tk such that there is no 
      C(tj, ri) > C(tk, ri) { As tk is the tile with the most conflicts, we choose to move it out of ri } 
     C(tk, ri) = 0 
     For every tile tj which had been in conflict with tk 
      C(tj, ri) = C(tj, ri) - 1 
     lc(s, ri) = lc(s, ri) + 1 
{ Check similarly for linear conflicts in each column ci, computing lc(s, cj). } 
LC(s) = 2[lc(s, r1) + . .. + lc(s, rL) + lc(s,ci) + . . . + lc(s, cL)] 
For each tile tj in s 
    determine md(s, tj) 
MD(s) = ms(s, t1) + ... + md(s, tn) 
h(s) = MD(s) + LC(s) 

Dieser Algorithmus des h heuristisch Kosten berechnet (n)

Verwandte Themen