Skip to content

Commit

Permalink
240430.233715.HKT fix "enumerator PRIMA_RESULT_INITIALIZED in switch …
Browse files Browse the repository at this point in the history
…of enum prima_rc_t is not explicitly handled by a case label"
  • Loading branch information
zaikunzhang committed Apr 30, 2024
1 parent dd02831 commit 5934728
Showing 1 changed file with 55 additions and 52 deletions.
107 changes: 55 additions & 52 deletions c/prima.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,60 @@ prima_rc_t prima_check_problem(const prima_problem_t problem, const prima_algori
}


// Function to get the string corresponding to the return code
const char *prima_get_rc_string(const prima_rc_t rc)
{
switch (rc) {
case PRIMA_SMALL_TR_RADIUS:
return "Trust region radius reaches its lower bound";
case PRIMA_FTARGET_ACHIEVED:
return "The target function value is reached";
case PRIMA_TRSUBP_FAILED:
return "A trust region step failed to reduce the model";
case PRIMA_MAXFUN_REACHED:
return "Maximum number of function evaluations reached";
case PRIMA_MAXTR_REACHED:
return "Maximum number of trust region iterations reached";
case PRIMA_NAN_INF_X:
return "The input X contains NaN of Inf";
case PRIMA_NAN_INF_F:
return "The objective or constraint functions return NaN or +Inf";
case PRIMA_NAN_INF_MODEL:
return "NaN or Inf occurs in the model";
case PRIMA_NO_SPACE_BETWEEN_BOUNDS:
return "No space between bounds";
case PRIMA_DAMAGING_ROUNDING:
return "Rounding errors are becoming damaging";
case PRIMA_ZERO_LINEAR_CONSTRAINT:
return "One of the linear constraints has a zero gradient";
case PRIMA_CALLBACK_TERMINATE:
return "Callback function requested termination of optimization";
case PRIMA_INVALID_INPUT:
return "Invalid input";
case PRIMA_ASSERTION_FAILS:
return "Assertion fails";
case PRIMA_VALIDATION_FAILS:
return "Validation fails";
case PRIMA_MEMORY_ALLOCATION_FAILS:
return "Memory allocation fails";
case PRIMA_NULL_OPTIONS:
return "NULL options";
case PRIMA_NULL_PROBLEM:
return "NULL problem";
case PRIMA_NULL_X0:
return "NULL x0";
case PRIMA_NULL_RESULT:
return "NULL result";
case PRIMA_NULL_FUNCTION:
return "NULL function";
case PRIMA_RESULT_INITIALIZED
return "Result is initialized but not properly set";
default:
return "Invalid return code";
}
}


// Function to initialize the result
prima_rc_t prima_init_result(prima_result_t *const result, const prima_problem_t problem)
{
Expand All @@ -96,7 +150,7 @@ prima_rc_t prima_init_result(prima_result_t *const result, const prima_problem_t
result->status = PRIMA_RESULT_INITIALIZED;

// message: exit message
result->message = NULL;
result->message = prima_get_rc_string(result->status);

// x: returned point
result->x = (double*)malloc(problem.n * sizeof(double));
Expand Down Expand Up @@ -136,57 +190,6 @@ prima_rc_t prima_free_result(prima_result_t *const result)
}


// Function to get the string corresponding to the return code
const char *prima_get_rc_string(const prima_rc_t rc)
{
switch (rc) {
case PRIMA_SMALL_TR_RADIUS:
return "Trust region radius reaches its lower bound";
case PRIMA_FTARGET_ACHIEVED:
return "The target function value is reached";
case PRIMA_TRSUBP_FAILED:
return "A trust region step failed to reduce the model";
case PRIMA_MAXFUN_REACHED:
return "Maximum number of function evaluations reached";
case PRIMA_MAXTR_REACHED:
return "Maximum number of trust region iterations reached";
case PRIMA_NAN_INF_X:
return "The input X contains NaN of Inf";
case PRIMA_NAN_INF_F:
return "The objective or constraint functions return NaN or +Inf";
case PRIMA_NAN_INF_MODEL:
return "NaN or Inf occurs in the model";
case PRIMA_NO_SPACE_BETWEEN_BOUNDS:
return "No space between bounds";
case PRIMA_DAMAGING_ROUNDING:
return "Rounding errors are becoming damaging";
case PRIMA_ZERO_LINEAR_CONSTRAINT:
return "One of the linear constraints has a zero gradient";
case PRIMA_CALLBACK_TERMINATE:
return "Callback function requested termination of optimization";
case PRIMA_INVALID_INPUT:
return "Invalid input";
case PRIMA_ASSERTION_FAILS:
return "Assertion fails";
case PRIMA_VALIDATION_FAILS:
return "Validation fails";
case PRIMA_MEMORY_ALLOCATION_FAILS:
return "Memory allocation fails";
case PRIMA_NULL_OPTIONS:
return "NULL options";
case PRIMA_NULL_PROBLEM:
return "NULL problem";
case PRIMA_NULL_X0:
return "NULL x0";
case PRIMA_NULL_RESULT:
return "NULL result";
case PRIMA_NULL_FUNCTION:
return "NULL function";
default:
return "Invalid return code";
}
}

// The function that does the minimization using a PRIMA solver
prima_rc_t prima_minimize(const prima_algorithm_t algorithm, const prima_problem_t problem, const prima_options_t options, prima_result_t *const result)
{
Expand Down

0 comments on commit 5934728

Please sign in to comment.