### java

#### Linear Conflict violating admissibility and driving me insane

When Two tiles tj and tk are in a linear conflict if tj and tk are in the same line, the goal positions of tj and tk are both in that line, tj is to the right of tk and goal position of tj is to the left of the goal position of tk. The linear conflict adds at least two moves to the Manhattan Distance of the two conflicting tiles, by forcing them to surround one another. Therefore the heuristic function will add a cost of 2 moves for each pair of conflicting tiles. The Linar Conflict Heuristic is admissible, but the algorithm I am using sometimes violates admissibility meaning it is pessimistic and will not necessarily find an optimal position. Here is the 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; } The algorithm violates admissibility when: Say we are focusing on one row which has the configuration [ 3, 1, 2 ] Let's assume [ 1, 2, 3 ] is the goal configuration. The summed manhattan distance for the problem is: 4 (3 moves 2 times, 1 moves 1 time and 2 moves 1 time) The linear conflict for the row is: 4 ( 1 and 2 are both less than 3 so +2+2 ) Which results in an overall heuristic estimate of 8. [ 3, 1, 2 ] can be solved in 6 moves,

The linear conflict heuristic is more complicated than just adding 2 for each pair of conflicting tiles. The heuristic is described 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) The algorithm is described in figure 5 and involves computing the minimum number of extra moves to resolve all conflicts in a row. As you have discovered, this is not equal to twice the number of conflicting pairs. The algorithm actually presented is: 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) This algorithm computes the heuristic cost h(s)

### Related Links

Simple question about java SimpleDateFormat

Get view from Widget reference

How to play .swf with flash player lite in android 2.2 sdk in java?

Find Specific Color in an Image

JodaTime with JPA, PostgreSQL and NULL values

Why do I get an AccessControlException while using RMI from an applet?

Java, android - help me understand code please

Maven release plugin : Releasing with a SNAPSHOT version

Tint Bitmap with Paint?

GWT - Oracle JDBC Connection problems

Am I writing this method the right way?

How to create a reminder using Alarm which can be editable in future

deploy servlet-war into oc4j container

Number format exception

Shutting down SSL without closing underlying socket?

Java MIDI Sequencer alternatives