Commit 364204c4 authored by Andrey Filippov's avatar Andrey Filippov

working on conflicts

parent 18261553
......@@ -116,7 +116,12 @@ public class Conflicts {
num_ortho_dual += conf.getDualTriOrthoDiagOrthoConflicts();
num_conflicts += conf.getNumConflicts();
if (debugLevel > 0){
printConflict("addConflicts() nsTile = "+nsTile+" ", conf);
int tilesX = st.tileProcessor.getTilesX();
int superTileSize = st.tileProcessor.getSuperTileSize();
int stilesX = (tilesX + superTileSize -1)/superTileSize;
int ty = nsTile / stilesX;
int tx = nsTile % stilesX;
printConflict("addConflicts() nsTile = "+nsTile+" ["+tx+":"+ty+"] ", conf);
}
}
}
......@@ -137,7 +142,12 @@ public class Conflicts {
num_ortho_dual += conf.getDualTriOrthoDiagOrthoConflicts();
num_conflicts += conf.getNumConflicts();
if (debugLevel > 0){
printConflict("addConflicts() nsTile = "+nsTile+" ", conf);
int tilesX = st.tileProcessor.getTilesX();
int superTileSize = st.tileProcessor.getSuperTileSize();
int stilesX = (tilesX + superTileSize -1)/superTileSize;
int ty = nsTile / stilesX;
int tx = nsTile % stilesX;
printConflict("addConflicts() nsTile = "+nsTile+" ["+tx+":"+ty+"] ", conf);
}
}
}
......
......@@ -2185,6 +2185,7 @@ public class EyesisCorrectionParameters {
public double plStarDiag = 0.25; // When calculating cost for the connections scale 4 diagonal neighbors
public double plStarPwr = 0.5; // Divide cost by number of connections to this power
public double plDblTriLoss = 0.0001; // When resolving double triangles allow minor degradation (0.0 - strict)
public boolean plNewConfl = false; // Allow more conflicts if overall cost is reduced
public boolean plMutualOnly = true; // keep only mutual links, remove weakest if conflict
public boolean plFillSquares = true; // Add diagonals to full squares
......@@ -2543,6 +2544,7 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"plStarDiag", this.plStarDiag +"");
properties.setProperty(prefix+"plStarPwr", this.plStarPwr +"");
properties.setProperty(prefix+"plDblTriLoss", this.plDblTriLoss +"");
properties.setProperty(prefix+"plNewConfl", this.plNewConfl+"");
properties.setProperty(prefix+"plMutualOnly", this.plMutualOnly+"");
properties.setProperty(prefix+"plFillSquares", this.plFillSquares+"");
......@@ -2881,6 +2883,7 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"plStarDiag")!=null) this.plStarDiag=Double.parseDouble(properties.getProperty(prefix+"plStarDiag"));
if (properties.getProperty(prefix+"plStarPwr")!=null) this.plStarPwr=Double.parseDouble(properties.getProperty(prefix+"plStarPwr"));
if (properties.getProperty(prefix+"plDblTriLoss")!=null) this.plDblTriLoss=Double.parseDouble(properties.getProperty(prefix+"plDblTriLoss"));
if (properties.getProperty(prefix+"plNewConfl")!=null) this.plNewConfl=Boolean.parseBoolean(properties.getProperty(prefix+"plNewConfl"));
if (properties.getProperty(prefix+"plMutualOnly")!=null) this.plMutualOnly=Boolean.parseBoolean(properties.getProperty(prefix+"plMutualOnly"));
if (properties.getProperty(prefix+"plFillSquares")!=null) this.plFillSquares=Boolean.parseBoolean(properties.getProperty(prefix+"plFillSquares"));
......@@ -3247,6 +3250,7 @@ public class EyesisCorrectionParameters {
gd.addNumericField("When calculating cost for the connections scale 4 diagonal neighbors", this.plStarDiag, 6);
gd.addNumericField("Divide cost by number of connections to this power", this.plStarPwr, 6);
gd.addNumericField("When resolving double triangles allow minor degradation (0.0 - strict)", this.plDblTriLoss, 6);
gd.addCheckbox ("Allow more conflicts if overall cost is reduced", this.plNewConfl);
gd.addCheckbox ("Keep only mutual links, remove weakest if conflict", this.plMutualOnly);
......@@ -3598,6 +3602,7 @@ public class EyesisCorrectionParameters {
this.plStarDiag= gd.getNextNumber();
this.plStarPwr= gd.getNextNumber();
this.plDblTriLoss= gd.getNextNumber();
this.plNewConfl= gd.getNextBoolean();
this.plMutualOnly= gd.getNextBoolean();
......
......@@ -4003,12 +4003,12 @@ public class SuperTiles{
", improvement (negative diff) = "+new_costs_diff_old);
}
if (debugLevel > -1) {
if (debugLevel > 0) { // -1) {
new_conflicts_stats.printConflictSummary(
"Conflicts difference after resolution:", true, true, true);
}
// See if it is good
if (debugLevel > -1) {
if (debugLevel > 0) { // -1) {
if (new_conflicts_stats.getNumConflicts() > 0) {
if (debugLevel > -1) System.out.println("FAILURE: number of conflicts increased");
} else if (new_costs_diff > dblTriLoss){
......@@ -4389,6 +4389,7 @@ public class SuperTiles{
double diagonalWeight,
double starPwr, // Divide cost by number of connections to this power
double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
boolean newConfl, // Allow more conflicts if overall cost is reduced
boolean preferDisparity,
int debugLevel,
int dbg_X,
......@@ -4416,11 +4417,12 @@ public class SuperTiles{
conflicts,
conflict_stats, // to be updated after applying resolution
// maxEigen, // maximal eigenvalue of planes to consider
starSteps, // How far to look around when calculationg connection cost
starSteps, // How far to look around when calculating connection cost
orthoWeight,
diagonalWeight,
starPwr, // double starPwr, // Divide cost by number of connections to this power
dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
newConfl, // boolean newConfl, // Allow more conflicts if overall cost is reduced
preferDisparity,
dl); // debugLevel,
if (OK) rslt[0]++;
......@@ -4444,9 +4446,14 @@ public class SuperTiles{
double diagonalWeight,
double starPwr, // Divide cost by number of connections to this power
double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
boolean newConfl, // Allow more conflicts if overall cost is reduced
boolean preferDisparity,
int debugLevel)
{
if (newConfl && (dblTriLoss > 0.0)){
dblTriLoss = 0.0; // require strict reducing of the cost if conflict increase is allowed
}
Conflicts iconflicts = new Conflicts(this);
TwoLayerNeighbors twoLayerNeighbors = new TwoLayerNeighbors();
......@@ -4462,8 +4469,11 @@ public class SuperTiles{
}
}
twoLayerNeighbors.setLayers(nl1, nl2);
if (debugLevel > 1) {
System.out.println("resolveStarConflict(): nsTile ="+nsTile+" nl1="+nl1+" nl2="+nl2);
}
int [][][][] neibs_vars_dir = twoLayerNeighbors.getNeighborVariants();
int [][][][] neibs_vars_dir = twoLayerNeighbors.getNeighborVariants(debugLevel);
int [] mod_supertiles = {nsTile};
mod_supertiles = getInvolvedSupertiles( // first mod_supertiles.length entries will be mod_supertiles[]
......@@ -4481,7 +4491,13 @@ public class SuperTiles{
for (int dir = -1; dir < 8; dir++){
int nindx = (dir < 0) ? 8 : dir;
int nt = tnSurface.getNeibIndex(nsTile, dir);
int indx = replacement_tiles.get(nt);
int indx = -1;
Integer Indx = replacement_tiles.get(nt);
if (Indx == null){
System.out.println("resolveStarConflict(): nsTile = "+nsTile+" nindx="+nindx+" Indx == null ");
} else {
indx = Indx;
}
if (indx >= 0) {
indexToDir[indx] = nindx;
}
......@@ -4546,7 +4562,7 @@ public class SuperTiles{
double [] variant_costs_diff = new double [neibs_vars.length];
for (int variant = 0; variant < neibs_vars.length; variant ++){
if (debugLevel > 0) {
if (debugLevel > 1) {
System.out.println("resolveStarConflict(): resolving conflict for tile "+nsTile+
", nl1 = "+nl1+
", nl2 = "+nl2 +
......@@ -4557,12 +4573,11 @@ public class SuperTiles{
neibs_vars[variant],
debugLevel);
if (debugLevel > -1) {
if (debugLevel > 0) {
System.out.println("resolveStarConflict(): resolving conflict for tile "+nsTile+
", nl1 = "+nl1+
", nl2 = "+nl2 +
", variant = "+variant+" improvement (negative diff) = "+variant_costs_diff[variant]);
}
......@@ -4579,13 +4594,14 @@ public class SuperTiles{
debugLevel - 1); // debugLevel);
variant_conflicts_stats[variant].subConflicts(iconflicts); // subtract old number of different types of conflicts
if (debugLevel > -1) {
if (debugLevel > 0) { // -1) {
variant_conflicts_stats[variant].printConflictSummary(
"Conflicts difference after resolution:", true, true, false);
}
}
// How to compare? 1 attempt: none of the conflicts get worse, some get better or cost goes down
int best_variant = -1;
int best_ignore_conflicts = -1;
int [][] num_better_worse = new int [neibs_vars.length][2];
for (int variant = 0; variant < neibs_vars.length; variant ++){
int num_worse = variant_conflicts_stats[variant].numBetterWorse(
......@@ -4610,12 +4626,23 @@ public class SuperTiles{
(variant_costs_diff[variant] < variant_costs_diff[best_variant])))){
best_variant = variant;
}
if ((best_ignore_conflicts <0) || (variant_costs_diff[variant] < variant_costs_diff[best_ignore_conflicts])){
best_ignore_conflicts = variant;
}
}
if (debugLevel > 1){
System.out.println("resolveStarConflict(): for tile "+nsTile);
}
if ((best_variant < 0) && newConfl && (variant_costs_diff[best_ignore_conflicts] < 0)){ // should be cost improvement
best_variant = best_ignore_conflicts;
if (debugLevel > -1) {
System.out.println("resolveMultiTriangularConflict(): conflicts increase but cost decreases "+nsTile+
", nl1 = "+nl1+
", nl2 = "+nl2 +" of "+ neibs_vars.length+" variants");
}
}
if ((best_variant < 0) || (variant_costs_diff[best_variant] > dblTriLoss)){
if (debugLevel > -1) {
System.out.println("resolveMultiTriangularConflict(): FAILED find a sutable solution for tile "+nsTile+
......@@ -4651,8 +4678,18 @@ public class SuperTiles{
// apply resolution
for (int i = 0; i < mod_supertiles.length; i++){
for (int nl = 0; nl < neibs_vars[best_variant][i].length; nl ++) if (neibs_vars[best_variant][i][nl] != null){
planes[mod_supertiles[i]][nl].setNeibBest(neibs_vars[best_variant][i][nl]);
if (debugLevel > 1){
System.out.println("resolveStarConflict(): nsTile = "+nsTile+ "mod_supertiles["+i+"]="+mod_supertiles[i]);
}
if (neibs_vars[best_variant][i] != null) {
for (int nl = 0; nl < neibs_vars[best_variant][i].length; nl ++){
if (debugLevel > 1){
System.out.println("resolveStarConflict(): nl= = "+nl);
}
if (neibs_vars[best_variant][i][nl] != null){
planes[mod_supertiles[i]][nl].setNeibBest(neibs_vars[best_variant][i][nl]);
}
}
}
}
}
......@@ -4919,7 +4956,8 @@ public class SuperTiles{
double diagonalWeight,
double starPwr, // Divide cost by number of connections to this power
double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
boolean preferDisparity,
boolean newConfl, // Allow more conflicts if overall cost is reduced
boolean preferDisparity,
int debugLevel,
int dbg_X,
int dbg_Y)
......@@ -4994,6 +5032,7 @@ public class SuperTiles{
diagonalWeight, // double diagonalWeight,
starPwr, // double starPwr, // Divide cost by number of connections to this power
dblTriLoss, // double diagonalWeight,
newConfl, // Allow more conflicts if overall cost is reduced
preferDisparity,
debugLevel, // 1, // final int debugLevel)
dbg_X,
......
......@@ -3440,6 +3440,7 @@ public class TileProcessor {
clt_parameters.plStarDiag, // double diagonalWeight,
clt_parameters.plStarPwr, // double starPwr, // Divide cost by number of connections to this power
clt_parameters.plDblTriLoss, // double diagonalWeight,
clt_parameters.plNewConfl, // boolean preferDisparity, // Allow more conflicts if overall cost is reduced
clt_parameters.plPreferDisparity,
1, // final int debugLevel)
clt_parameters.tileX,
......@@ -3546,6 +3547,7 @@ public class TileProcessor {
clt_parameters.plStarDiag, // double diagonalWeight,
clt_parameters.plStarPwr, // double starPwr, // Divide cost by number of connections to this power
clt_parameters.plDblTriLoss, // double diagonalWeight,
clt_parameters.plNewConfl, // boolean preferDisparity, // Allow more conflicts if overall cost is reduced
clt_parameters.plPreferDisparity,
1, // final int debugLevel)
clt_parameters.tileX,
......
......@@ -63,7 +63,7 @@ public class TwoLayerNeighbors {
int nl2;
NeibVariant neibs_init = new NeibVariant();
int [][] layers_around = new int [8][];
int [] options_around = new int [8];
int [] options_around = new int [8]; // how many tiles are connected to the center at this direction, from one of nl1, nl2
int [][] num_se = new int [PAIRS.length][];
int [][][] conns = new int [PAIRS.length][][];
int [] selection_star = null;
......@@ -124,11 +124,15 @@ public class TwoLayerNeighbors {
int dir1,
int nl1,
int dir2,
int nl2){
int nl2,
int debugLevel){
int dir12 = getDir2From1(dir1, dir2);
if (dir12 <0){
throw new IllegalArgumentException ("Invalid connection from "+dir1+" to "+dir2+": resulted in direction 1->2 = "+dir12);
}
if (debugLevel > 1){
System.out.print(" "+dir1+":"+nl1+"<->"+dir2+":"+nl2);
}
int dir21 = (dir12 + 4) % 8;
int [][] neibs_start = getNeighbors(dir1);
int [][] neibs_end = getNeighbors(dir2);
......@@ -153,6 +157,34 @@ public class TwoLayerNeighbors {
}
public void diffToOther(NeibVariant other_variant)
{
for (int dir0 = 0; dir0 < neighbors.length; dir0++){
if ((neighbors[dir0] != null) || (other_variant.neighbors[dir0] != null)){
if ((neighbors[dir0] == null) || (other_variant.neighbors[dir0] == null)){
System.out.print(" ["+dir0+"]");
} else {
for (int nl = 0; nl < neighbors[dir0].length; nl++){
if ((neighbors[dir0][nl] != null) || (other_variant.neighbors[dir0][nl] != null)){
if ((neighbors[dir0][nl] == null) || (other_variant.neighbors[dir0][nl] == null)){
System.out.print(" ["+dir0+":"+nl+"]");
} else {
for (int dir = 0; dir < 8; dir++){
if (neighbors[dir0][nl][dir] != other_variant.neighbors[dir0][nl][dir]){
System.out.print(" "+dir0+":"+nl+":"+dir+":("+neighbors[dir0][nl][dir]+"/"+
other_variant.neighbors[dir0][nl][dir]+")");
}
}
}
}
}
}
}
}
System.out.println();
}
}
/**
......@@ -167,12 +199,6 @@ public class TwoLayerNeighbors {
} else {
// increment connection variant if possible
for (int np = 0; np < PAIRS.length; np++){
// if (
// (num_se[np] == null) ||
// (conns[np] == null)) {
// System.out.println("nextSelection BUG");
// return false;
// }
if ((num_se[np] != null) && (num_se[np][0] == 2) && (num_se[np][1] == 2) && (conns[np] != null) && (conns[np].length == 1)){
if (selection_conns[np] == 0){
selection_conns[np] = 1;
......@@ -188,7 +214,7 @@ public class TwoLayerNeighbors {
selection_conns[i] = 0;
}
for (int dir = 0; dir < options_around.length; dir++){
if ((options_around[dir]>1) && (selection_star[dir] == 0)){
if ((options_around[dir] > 0) && (selection_star[dir] == 0)){ // either 1 or two layers connected - still 2 variants
selection_star[dir] = 1;
for (int dir1 = 0; dir1 < dir; dir1++){
selection_star[dir1] = 0;
......@@ -205,9 +231,9 @@ public class TwoLayerNeighbors {
* @return neibVariant instance fro the current selection or null if the
* selection leads to conflicts
*/
public NeibVariant generateVariant()
public NeibVariant generateVariant(int debugLevel)
{
// verify all connetions are possible
// verify all connections are possible
for (int np = 0; np < PAIRS.length; np++) if (conns[np] != null){
// single connection for a single variant for start and end - either match or not
if ((num_se[np] != null) && (conns[np].length == 1) && (num_se[np][0] == 1) && (num_se[np][1] == 1)){
......@@ -222,17 +248,31 @@ public class TwoLayerNeighbors {
NeibVariant variant = neibs_init.clone();
// set connections for the center
if (debugLevel > 1){
System.out.print("center connections:");
}
for (int dir = 0; dir < 8; dir++) if (options_around[dir] > 0){
// make a first connection, if there are two - other will be created simultaneously
variant.connect(
-1, // int dir1,
((selection_star[dir] > 0) ? nl2 : nl1), // int nl1,
dir, // int dir2,
layers_around[dir][0]); // int nl2);
layers_around[dir][0], // int nl2);
debugLevel);
}
if (debugLevel > 1){
System.out.println();
}
if (debugLevel > 1){
System.out.print("other connections:");
}
// set all other connections
for (int np = 0; np < PAIRS.length; np++) if (conns[np] != null){
if (debugLevel > 1){
System.out.print(" {"+np+"}");
}
int start_dir = PAIRS[np][0];
int end_dir = PAIRS[np][1];
boolean swap = (selection_star[start_dir] != selection_star[end_dir]) ^ (selection_conns[np] > 0);
......@@ -248,21 +288,39 @@ public class TwoLayerNeighbors {
start_dir, // int dir1,
layers_around[start_dir][opts[0]], // int nl1,
end_dir, // int dir2,
layers_around[end_dir][opts[1]]); // int nl2);
return variant;
layers_around[end_dir][opts[1]], // int nl2);
debugLevel);
}
return null;
if (debugLevel > 1){
System.out.println();
}
return variant;
}
public int [][][][] getNeighborVariants()
{
return getNeighborVariants(0);
}
public int [][][][] getNeighborVariants(int debugLevel)
{
ArrayList<NeibVariant> variant_list = new ArrayList<NeibVariant>();
while (nextSelection()){
NeibVariant variant = generateVariant();
NeibVariant variant = generateVariant(debugLevel);
if (variant != null){
variant_list.add(variant);
if (debugLevel > 0){
System.out.print("getNeighborVariants() "+(variant_list.size()-1)+": [");
for (int i = 0; i < selection_star.length; i++){
System.out.print(selection_star[i]);
}
System.out.print("] [");
for (int i = 0; i < selection_conns.length; i++){
System.out.print(selection_conns[i]);
}
System.out.print("]: ");
variant.diffToOther(neibs_init);
}
}
}
int [][][][] variants = new int [variant_list.size()][][][];
int indx = 0;
......@@ -327,7 +385,7 @@ public class TwoLayerNeighbors {
public void setLayers(int nl1, int nl2)
{
this.nl1 = nl1;
this.nl2 = nl1;
this.nl2 = nl2;
layers_around = new int [8][];
options_around = new int [8];
int [][] neighbors_center = neibs_init.getNeighbors(-1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment