Ejemplo n.º 1
0
/* The gateway function */
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    char *problem_suite;
    int findex;
    coco_problem_t *pb = NULL;
    long long *res; 

    /* check for proper number of arguments */
    if(nrhs!=2) {
        mexErrMsgIdAndTxt("cocoSuiteGetProblem:nrhs","Two inputs required.");
    }
    /* get problem_suite */
    problem_suite = mxArrayToString(prhs[0]);
    /* get function_index */
    findex = (int)mxGetScalar(prhs[1]);
    /* call coco_suite_get_problem() */
    pb = coco_suite_get_problem(problem_suite, findex);
    /* prepare the return value */
    plhs[0] = mxCreateNumericMatrix(1, 1 ,mxINT64_CLASS, mxREAL);
    res = (long long *)mxGetData(plhs[0]);
    *res = (long long)pb;   
}
Ejemplo n.º 2
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;
}