checkpoint
[anneal.git] / src / edu / berkeley / qfat / Main.java
index 7eb7b09..dac265b 100644 (file)
@@ -35,6 +35,8 @@ public class Main extends MeshViewer {
             Mesh.T t  = goal.newT(p0, p1, p2, n, 0);
         }
 
+        goal.ignorecollision = true;
+
         // rotate to align major axis -- this probably needs to be done by a human.
         goal.transform(new Matrix(new Vec(0, 0, 1), (float)(Math.PI/2)));
 
@@ -47,9 +49,9 @@ public class Main extends MeshViewer {
         float height = (float)0.08;
         float depth  = (float)0.3;
         */
-        float width  = (float)0.6;
+        float width  = (float)0.7;
         float depth  = (float)0.08;
-        float height = (float)0.3;
+        float height = (float)0.35;
 
         float rshift = width/2;
         float lshift = -(width/2);
@@ -63,12 +65,6 @@ public class Main extends MeshViewer {
             new Matrix(new Vec(rshift,  depth,    halfup)),
             new Matrix(new Vec(lshift, -depth,    halfup)),
             new Matrix(new Vec(rshift, -depth,    halfup)),
-            /*
-            new Matrix(new Vec(lshift,  depth,   -halfup)),
-            new Matrix(new Vec(rshift,  depth,   -halfup)),
-            new Matrix(new Vec(lshift, -depth,   -halfup)),
-            new Matrix(new Vec(rshift, -depth,   -halfup)),
-            */
 
             new Matrix(new Vec(lshift,       0,  height)),
             new Matrix(new Vec(rshift,       0,  height)),
@@ -77,6 +73,7 @@ public class Main extends MeshViewer {
 
             new Matrix(new Vec( width,           0,    0)),
             new Matrix(new Vec(-width,           0,    0)),
+
         };
 
 
@@ -231,6 +228,7 @@ public class Main extends MeshViewer {
 
         tile.score_against = goal;
         goal.score_against = tile;
+        tile.tilemesh = true;
     }
 
     public synchronized void breakit() {
@@ -238,7 +236,7 @@ public class Main extends MeshViewer {
         //while(verts < 800) {
         PriorityQueue<Mesh.E> es = new PriorityQueue<Mesh.E>();
         for(Mesh.E e : tile.edges()) es.add(e);
-        for(int i=0; i<8; i++) {
+        for(int i=0; i<10; i++) {
             Mesh.E e = es.poll();
             verts++;
             System.out.println("shatter " + e);
@@ -249,19 +247,23 @@ public class Main extends MeshViewer {
     }
 
     public synchronized void rand(float temp, Mesh.Vert p) {
-        double tile_score = tile.score();
-        double goal_score = goal.score();
 
         //p.reComputeError();
         p.reComputeErrorAround();
+        double tile_score = tile.score();
+        double goal_score = goal.score();
 
-        Vec v = new Vec((random.nextFloat() - (float)0.5) / 400,
-                        (random.nextFloat() - (float)0.5) / 400,
-                        (random.nextFloat() - (float)0.5) / 400);
-        /*
+        Vec v;
         Matrix inv = p.errorQuadric();
-        Vec v = new Vec(inv.d, inv.h, inv.l).norm().times(1/(float)1000);
-        */
+        v = new Vec(inv.d, inv.h, inv.l).norm().times(1/(float)1000);
+        if (p.quadric_count == 0) {
+            v = goal.nearest(p.p).p.minus(p.p).norm().times(1/(float)1000);
+        }
+        Vec v2 = new Vec((random.nextFloat() - (float)0.5) / 500,
+                        (random.nextFloat() - (float)0.5)  / 500,
+                        (random.nextFloat() - (float)0.5)  / 500);
+        v = v.plus(v2.norm().times(1/(float)1000));
+
         boolean good = p.move(v);
 
         p.reComputeErrorAround();
@@ -272,8 +274,8 @@ public class Main extends MeshViewer {
         double goal_delta = (new_goal_score - goal_score) / goal_score;
         double delta = tile_delta + goal_delta;
         double swapProbability = Math.exp((-1 * delta) / temp);
-        boolean doSwap = good && (Math.random() < swapProbability);
-        //boolean doSwap = good && (tile_delta <= 0 && goal_delta <= 0);
+        //boolean doSwap = good && (Math.random() < swapProbability);
+        boolean doSwap = good && (tile_delta <= 0 && goal_delta <= 0);
         if (doSwap) {
             tile_score = new_tile_score;
             goal_score = new_goal_score;
@@ -302,23 +304,26 @@ public class Main extends MeshViewer {
             if (breaks) {
                 breaks = false;
                     breakit();
-                    gamma = 2;
+                    //gamma = 1;
+                    gamma = 1;
                     //temp = last * 0.8f;
                     //last = temp;
                     //temp = hightemp;
             } else
-            if (acceptance > 0.96) gamma = 0.6f;
-            else if (acceptance > 0.9) gamma = 0.7f;
-            else if (acceptance > 0.8) gamma = 0.75f;
-            else if (acceptance > 0.6) gamma = 0.8f;
+            if (acceptance > 0.96) gamma = 0.4f;
+            else if (acceptance > 0.9) gamma = 0.5f;
+            else if (acceptance > 0.8) gamma = 0.65f;
+            else if (acceptance > 0.6) gamma = 0.7f;
             else {
                 if (acceptance > 0.3) {
                     gamma = 0.9f;
                 } else if (acceptance > 0.15) {
                     gamma = 0.95f;
                 } else {
-                    breakit();
-                    gamma = 2;
+                    //breakit();
+                    //gamma = 1;
+                    gamma = 0.99f;
+                    //gamma = 1;
                     //temp = last * 0.8f;
                     //last = temp;
                     //temp = hightemp;
@@ -346,7 +351,8 @@ public class Main extends MeshViewer {
 
     public static void main(String[] s) throws Exception {
         StlFile stlf = new StlFile();
-        stlf.load("simplefish.stl");
+        stlf.load("fish.stl");
+        //stlf.load("monkey.stl");
         Frame f = new Frame();
         Main main = new Main(stlf, f);
         f.pack();