]> mj.ucw.cz Git - leo.git/blobdiff - labeller.c
Labelling: randdouble implementation
[leo.git] / labeller.c
index b7b8ee4cdbc43d58d2b1b859bc0a033f2b687504..f2792ee091b8912e17e1328abc88c50761c88db6 100644 (file)
@@ -122,6 +122,8 @@ void elite(void);
 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);
@@ -1348,6 +1350,14 @@ int individual_overlap(struct individual *individual)
   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)
 {
   int penalty;
@@ -1700,8 +1710,7 @@ int flip(int a, int b)
 
 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)