[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15626] branches/harmonic-skeleton/source/ blender/src/autoarmature.c: Exponential cooling off and progressive minimization for simulated annealing

Martin Poirier theeth at yahoo.com
Fri Jul 18 21:09:41 CEST 2008


Revision: 15626
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15626
Author:   theeth
Date:     2008-07-18 21:09:41 +0200 (Fri, 18 Jul 2008)

Log Message:
-----------
Exponential cooling off and progressive minimization for simulated annealing

Modified Paths:
--------------
    branches/harmonic-skeleton/source/blender/src/autoarmature.c

Modified: branches/harmonic-skeleton/source/blender/src/autoarmature.c
===================================================================
--- branches/harmonic-skeleton/source/blender/src/autoarmature.c	2008-07-18 19:03:50 UTC (rev 15625)
+++ branches/harmonic-skeleton/source/blender/src/autoarmature.c	2008-07-18 19:09:41 UTC (rev 15626)
@@ -592,6 +592,19 @@
 	printf("\n");
 }
 
+static void printMovesNeeded(int *positions, int nb_positions)
+{
+	int moves = 0;
+	int i;
+	
+	for (i = 0; i < nb_positions; i++)
+	{
+		moves += positions[i] - (i + 1);
+	}
+	
+	printf("%i moves needed\n", moves);
+}
+
 static void printPositions(int *positions, int nb_positions)
 {
 	int i;
@@ -810,7 +823,7 @@
 	}
 	else
 	{
-		return (float)exp(delta_cost) * temperature;
+		return (float)exp(delta_cost / temperature);
 	}
 }
 
@@ -1069,7 +1082,9 @@
 		float *cost_cube;
 		float cost;
 #ifdef ANNEALING_ITERATION
-		int k, kmax = 100000;
+		int k;
+		//int kmax = 100000;
+		int kmax = nb_joints * earc->bcount * 200;
 #else
 		double time_start, time_current, time_length = 3;
 		int k;
@@ -1102,6 +1117,7 @@
 		}
 		
 		printf("initial cost: %f\n", cost);
+		printf("kmax: %i\n", kmax);
 		
 #ifdef ANNEALING_ITERATION
 		for (k = 0; k < kmax; k++)
@@ -1121,6 +1137,12 @@
 			
 			if (status == 0)
 			{
+				/* if current state is still a minimum, copy it */
+				if (cost < min_cost)
+				{
+					min_cost = cost;
+					memcpy(best_positions, positions, sizeof(int) * nb_joints);
+				}
 				break;
 			}
 			
@@ -1143,6 +1165,13 @@
 				
 				cost += delta_cost;
 	
+				/* cost optimizing */
+				if (cost < min_cost)
+				{
+					min_cost = cost;
+					memcpy(best_positions, positions, sizeof(int) * nb_joints);
+				}
+
 				/* update cost cube */			
 				for (previous = iarc->edges.first, edge = previous->next, i = 0;
 					 edge;
@@ -1157,12 +1186,12 @@
 				}
 			}
 		}
+
+		//min_cost = cost;
+		//memcpy(best_positions, positions, sizeof(int) * nb_joints);
 		
-		min_cost = cost;
-		
 //		printf("k = %i\n", k);
 		
-		memcpy(best_positions, positions, sizeof(int) * nb_joints);
 		
 		MEM_freeN(cost_cube);
 	}	
@@ -1251,6 +1280,7 @@
 	initArcIterator(&iter, earc, node_start);
 	
 	printPositions(best_positions, nb_joints);
+	printMovesNeeded(best_positions, nb_joints);
 	printf("min_cost %f\n", min_cost);
 	printf("buckets: %i\n", earc->bcount);
 





More information about the Bf-blender-cvs mailing list