Ejemplo n.º 1
0
static void transformed_free_problem(coco_problem_t *self) {
  coco_transformed_data_t *data;

  assert(self != NULL);
  assert(self->data != NULL);
  data = self->data;
  assert(data->inner_problem != NULL);

  if (data->inner_problem != NULL) {
    coco_problem_free(data->inner_problem);
    data->inner_problem = NULL;
  }
  if (data->data != NULL) {
    if (data->free_data != NULL) {
      data->free_data(data->data);
      data->free_data = NULL;
    }
    coco_free_memory(data->data);
    data->data = NULL;
  }
  /* Let the generic free problem code deal with the rest of the
   * fields. For this we clear the free_problem function pointer and
   * recall the generic function.
   */
  self->free_problem = NULL;
  coco_problem_free(self);
}
Ejemplo n.º 2
0
static void coco_stacked_problem_free(coco_problem_t *self) {
  coco_stacked_problem_data_t *data;

  assert(self != NULL);
  assert(self->data != NULL);
  data = self->data;

  if (data->problem1 != NULL) {
    coco_problem_free(data->problem1);
    data->problem1 = NULL;
  }
  if (data->problem2 != NULL) {
    coco_problem_free(data->problem2);
    data->problem2 = NULL;
  }
  if (data->data != NULL) {
    if (data->free_data != NULL) {
      data->free_data(data->data);
      data->free_data = NULL;
    }
    coco_free_memory(data->data);
    data->data = NULL;
  }
  /* Let the generic free problem code deal with the rest of the
   * fields. For this we clear the free_problem function pointer and
   * recall the generic function.
   */
  self->free_problem = NULL;
  coco_problem_free(self);
}
Ejemplo n.º 3
0
/**
 * @brief Frees the stacked problem.
 */
static void coco_problem_stacked_free(coco_problem_t *problem) {
  coco_problem_stacked_data_t *data;

  assert(problem != NULL);
  assert(problem->data != NULL);
  data = (coco_problem_stacked_data_t*) problem->data;

  if (data->problem1 != NULL) {
    coco_problem_free(data->problem1);
    data->problem1 = NULL;
  }
  if (data->problem2 != NULL) {
    coco_problem_free(data->problem2);
    data->problem2 = NULL;
  }
  /* Let the generic free problem code deal with the rest of the fields. For this we clear the free_problem
   * function pointer and recall the generic function. */
  problem->problem_free_function = NULL;
  coco_problem_free(problem);
}
Ejemplo n.º 4
0
/**
 * @brief Frees the transformed problem.
 */
static void coco_problem_transformed_free(coco_problem_t *problem) {
  coco_problem_transformed_data_t *data;

  assert(problem != NULL);
  assert(problem->data != NULL);
  data = (coco_problem_transformed_data_t *) problem->data;
  assert(data->inner_problem != NULL);
  if (data->inner_problem != NULL) {
    coco_problem_free(data->inner_problem);
    data->inner_problem = NULL;
  }
  coco_problem_transformed_free_data(problem);
}
Ejemplo n.º 5
0
/**
 * @brief Frees the Lunacek bi-Rastrigin data object.
 */
static void f_lunacek_bi_rastrigin_free(coco_problem_t *problem) {
  f_lunacek_bi_rastrigin_data_t *data;
  data = (f_lunacek_bi_rastrigin_data_t *) problem->data;
  coco_free_memory(data->x_hat);
  coco_free_memory(data->z);
  coco_free_memory(data->xopt);
  bbob2009_free_matrix(data->rot1, problem->number_of_variables);
  bbob2009_free_matrix(data->rot2, problem->number_of_variables);

  /* Let the generic free problem code deal with all of the
   * coco_problem_t fields.
   */
  problem->problem_free_function = NULL;
  coco_problem_free(problem);
}
Ejemplo n.º 6
0
/* The gateway function */
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    char *problem_suite;
    coco_problem_t *problem = NULL;
    long long *ref;

    /* check for proper number of arguments */
    if(nrhs!=1) {
        mexErrMsgIdAndTxt("cocoProblemFree:nrhs","One input required.");
    }
    /* get the problem */
    ref = (long long *)mxGetData(prhs[0]);
    problem = (coco_problem_t *)(*ref);
    /* call coco_problem_free() */
    coco_problem_free(problem);
}
Ejemplo n.º 7
0
static void f_gallagher_free(coco_problem_t *self) {
  f_gallagher_data_t *data;
  data = self->data;
  coco_free_memory(data->xopt);
  coco_free_memory(data->peak_values);
  bbob2009_free_matrix(data->rotation, self->number_of_variables);
  bbob2009_free_matrix(data->x_local, self->number_of_variables);
  bbob2009_free_matrix(data->arr_scales, data->number_of_peaks);
  self->free_problem = NULL;
  coco_problem_free(self);

  if (gallagher_peaks != NULL) {
    coco_free_memory(gallagher_peaks);
    gallagher_peaks = NULL;
  }
}
Ejemplo n.º 8
0
/**
 * @brief Frees only the data of the transformed problem leaving the inner problem intact.
 *
 * @note If there is no other pointer to the inner problem, access to it will be lost.
 */
static void coco_problem_transformed_free_data(coco_problem_t *problem) {
  coco_problem_transformed_data_t *data;

  assert(problem != NULL);
  assert(problem->data != NULL);
  data = (coco_problem_transformed_data_t *) problem->data;

  if (data->data != NULL) {
    if (data->data_free_function != NULL) {
      data->data_free_function(data->data);
      data->data_free_function = NULL;
    }
    coco_free_memory(data->data);
    data->data = NULL;
  }
  /* Let the generic free problem code deal with the rest of the fields. For this we clear the free_problem
   * function pointer and recall the generic function. */
  problem->problem_free_function = NULL;
  coco_problem_free(problem);
}
Ejemplo n.º 9
0
int main(int argc, char **argv) {
  int header_shown = 0, number_of_failures = 0, shown_failures = 0;
  size_t number_of_testvectors = 0, i, j;
  int number_of_testcases = 0;
  testvector_t *testvectors = NULL;
  long previous_problem_index = -1;
  size_t problem_index_old, problem_index;
  int testvector_id, ret;
  coco_problem_t *problem = NULL;
  char suit_name[128];
  FILE *testfile = NULL;
  coco_suite_t *suite;

  if (argc != 2) {
    usage(argv[0]);
    goto err;
  }

  testfile = fopen(argv[1], "r");
  if (testfile == NULL) {
    fprintf(stderr, "Failed to open testcases file %s.\n", argv[1]);
    goto err;
  }

  ret = fscanf(testfile, "%127s", suit_name);
  if (ret != 1) {
    fprintf(stderr, "Failed to read suite name from testcases file.\n");
    goto err;
  }

  ret = fscanf(testfile, "%30lu", &number_of_testvectors);
  if (ret != 1) {
    fprintf(stderr,
            "Failed to read number of test vectors from testcases file.\n");
    goto err;
  }

  testvectors = malloc(number_of_testvectors * sizeof(*testvectors));
  if (NULL == testvectors) {
    fprintf(stderr, "Failed to allocate memory for testvectors.\n");
    goto err;
  }

  for (i = 0; i < number_of_testvectors; ++i) {
    for (j = 0; j < 40; ++j) {
      ret = fscanf(testfile, "%30lf", &testvectors[i].x[j]);
      if (ret != 1) {
        fprintf(stderr, "ERROR: Failed to parse testvector %lu element %lu.\n",
        		(unsigned long) i + 1, (unsigned long) j + 1);
      }
    }
  }

  suite = coco_suite("bbob", "instances: 1-15", NULL);

  while (1) {
    double expected_value, *x, y;
    ret = fscanf(testfile, "%30lu\t%30lu\t%30i\t%30lf", &problem_index_old, &problem_index, &testvector_id,
                 &expected_value);
    if (ret != 4)
      break;
    ++number_of_testcases;
    /* We cache the problem object to save time. Instantiating
     * some functions is expensive because we have to generate
     * large rotation matrices.
     */
    if (previous_problem_index != (long) problem_index) {
      if (NULL != problem)
        coco_problem_free(problem);
      if (problem_index > coco_suite_get_number_of_problems(suite) - 1) {
        fprintf(stdout, "problem index = %lu, maximum index = %lu \n", (unsigned long) problem_index,
        		(unsigned long) coco_suite_get_number_of_problems(suite) - 1);
      }
      problem = coco_suite_get_problem(suite, problem_index);
      previous_problem_index = (long) problem_index;
    }
    x = testvectors[testvector_id].x;

    coco_evaluate_function(problem, x, &y);
    if (!about_equal(expected_value, y)) {
      ++number_of_failures;
      if (!header_shown) {
        fprintf(stdout, "Problem Testcase Status Message\n");
        header_shown = 1;
      }
      if (shown_failures < 100) {
        fprintf(stdout,
                "%8lu %8i FAILED expected=%.8e observed=%.8e problem_id=%s\n",
                problem_index, testvector_id, expected_value, y,
                coco_problem_get_id(problem));
        fflush(stdout);
        ++shown_failures;
      } else if (shown_failures == 100) {
        fprintf(stdout, "... further failed tests suppressed ...\n");
        fflush(stdout);
        ++shown_failures;
      }
    }
  }
  fclose(testfile);
  /* Output summary statistics */
  fprintf(stderr, "%i of %i tests passed (failure rate %.2f%%)\n",
          number_of_testcases - number_of_failures, (int)number_of_testcases,
          (100.0 * number_of_failures) / number_of_testcases);

  /* Free any remaining allocated memory */
  if (NULL != problem)
    coco_problem_free(problem);
  free(testvectors);

  coco_suite_free(suite);

  return number_of_failures == 0 ? 0 : 1;

err:
  if (testfile != NULL)
    fclose(testfile);
  if (testvectors != NULL)
    free(testvectors);
  return 2;
}