]> mj.ucw.cz Git - leo.git/blobdiff - labeller.c
Labelling: randdouble implementation
[leo.git] / labeller.c
index 3ccb6a1146f847ee8c4f745769832a93ced4d232..f2792ee091b8912e17e1328abc88c50761c88db6 100644 (file)
@@ -50,6 +50,7 @@ int dbg_map_parts = 0;
 int dbg_movement = 0;
 int dbg_init = 0;
 int dbg_overlaps = 0;
 int dbg_movement = 0;
 int dbg_init = 0;
 int dbg_overlaps = 0;
+int dbg_rank = 0;
 
 int page_width_int;
 int page_height_int;
 
 int page_width_int;
 int page_height_int;
@@ -121,6 +122,8 @@ void elite(void);
 void rank_population(void);
 void plan_individual(struct individual *individual);
 
 void rank_population(void);
 void plan_individual(struct individual *individual);
 
+int cmp_individual(const void *a, const void *b);
+
 void make_bitmap(struct variant *v, struct symbol *sym);
 void make_bitmap_icon(struct variant *v, struct sym_icon *si);
 void make_bitmap_point(struct variant *v, struct sym_point *sp);
 void make_bitmap(struct variant *v, struct symbol *sym);
 void make_bitmap_icon(struct variant *v, struct sym_icon *si);
 void make_bitmap_point(struct variant *v, struct sym_point *sp);
@@ -1347,9 +1350,29 @@ int individual_overlap(struct individual *individual)
   return overlap;
 }
 
   return overlap;
 }
 
+int cmp_individual(const void *a, const void *b)
+{
+  struct individual **ia = (struct individual **) a;
+  struct individual **ib = (struct individual **) b;
+
+  return (*ia)->penalty - (*ib)->penalty;
+}
+
 void rank_population(void)
 {
 void rank_population(void)
 {
-  // FIXME
+  int penalty;
+
+  for (int i=0; i<conf_pop_size; i++)
+  {
+    if (dbg_rank)
+      printf("Individual %d\n", i);
+    population1[i]->penalty = 0;
+
+    penalty = individual_overlap(population1[i]);
+    if (dbg_rank)
+      printf("Increasing penalty by %d for overlap\n", penalty);
+    population1[i]->penalty += penalty;
+  }
 }
 
 struct map_part **get_map_parts(struct placement *p)
 }
 
 struct map_part **get_map_parts(struct placement *p)
@@ -1687,8 +1710,7 @@ int flip(int a, int b)
 
 double randdouble(void)
 {
 
 double randdouble(void)
 {
-  // FIXME: How the hell shall double in range <0, 1> be generated? O:)
-  return 0.5;
+  return ((double) rand() / (double) RAND_MAX);
 }
 
 void cleanup(void)
 }
 
 void cleanup(void)