We follow the following coding style guidelines and recommend them for all developers.
Spacing:
- Indentation is 3 spaces. No tabs anywhere in the code.
Every opening parenthesis requires an additional indentation of 3 spaces.
"should strong branching result be considered for pseudo costs if the other direction was infeasible?",&branchruledata->storesemiinitcosts, TRUE, DEFAULT_STORESEMIINITCOSTS,SCIP_RETCODE SCIPaddBoolParam(SCIP *scip, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)Definition: scip_param.c:57Definition: multiprecision.hpp:66- Spaces around all operators.
- Spaces around the arguments inside an if/for/while-statement, as well as inside macros (e.g., SCIP_CALL).
- No spaces between control structure keywords like "if", "for", "while", "switch" and the corresponding brackets.
- No spaces between a function name and the parenthesis in both the definition and function calls.
- Braces are on a new line and not indented.
Braces in if/for-statements should only be omitted if they enclose a single line.
for( v = 0; v < nandvars; ++v ){/* get active index of operator */probindex = SCIPvarGetProbindex(SCIPvarGetProbvar(andvars[v]));/* the operator might be deleted */if( probindex >= 0 )++nlcount[probindex];}- In function declarations, every parameter is on a new line. The name of the parameter starts at column 26, the comment starts at column 46 (if column-count starts with 1).
- Maximal line length is 120 characters.
- Always only one declaration in a line.
Joint declaration and initialization is possible at the top-level of a function and in the header of loops.
for( int i = 0; i < cutnnz; ++i ){QUAD_ARRAY_LOAD(coef, cutcoefs, cutinds[i]);elseif( ! ignoresol ){SCIPquadprecProdQD(coef, coef, (sol == NULL ? SCIPvarGetLPSol(vars[cutinds[i]]) : SCIPgetSolVal(scip, sol, vars[cutinds[i]])));}else{if( cutcoefs[i] > 0.0 ){SCIPquadprecProdQD(coef, coef, (islocal ? SCIPvarGetLbLocal(vars[cutinds[i]]) : SCIPvarGetLbGlobal(vars[cutinds[i]])));}else{SCIPquadprecProdQD(coef, coef, (islocal ? SCIPvarGetUbLocal(vars[cutinds[i]]) : SCIPvarGetUbGlobal(vars[cutinds[i]])));}}SCIPquadprecSumQQ(activity, activity, coef);}SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)Definition: scip_sol.c:1765Variable names should be all lower case.
/** counts number of nonlinear constraints in which each variable appears */staticint* nlcount, /**< pointer to array for storing count values */int nlcountsize, /**< buffer for storing length of nlcount array */int* nlcountmax /**< buffer for storing maximum value in nlcount array */){SCIP_CONSHDLR* andconshdlr;SCIP_VAR** vars;int nvars;int i;static SCIP_RETCODE countNonlinearities(SCIP *scip, int *nlcount, int nlcountsize, int *nlcountmax)Definition: branch_relpscost.c:459Definition: struct_cons.h:128Definition: struct_var.h:262Definition: struct_scip.h:72- Blank lines are inserted where it improves readability.
Multiple blank lines are used to structure the code where single blank lines are insufficient, e.g., between differrent sections of the code.
/** execution method of primal heuristic */staticSCIP_DECL_HEUREXEC(heurExecXyz){ /*lint --e{715}*/SCIPerrorMessage("method of xyz primal heuristic not implemented yet\n");SCIPABORT(); /*lint --e{527}*/return SCIP_OKAY;}/** primal heuristic specific interface methods*//** creates the xyz primal heuristic and includes it in SCIP */SCIP_RETCODE SCIPincludeHeurXyz(){SCIP_HEURDATA* heurdata;SCIP_HEUR* heur;/* create xyz primal heuristic data */heurdata = NULL;heur = NULL;Definition: struct_heur.h:98
Naming:
- Use assert() to show preconditions for the parameters, invariants, and postconditions.
- Make all functions that are not used outside the module 'static'.
Naming should start with a lower case letter.
/** frees bound change arrays */staticvoid freeBdchgs(int** bdchginds, /**< pointer to bound change index array */SCIP_BOUNDTYPE** bdchgtypes, /**< pointer to bound change types array */SCIP_Real** bdchgbounds, /**< pointer to bound change new bounds array */int* nbdchgs /**< pointer to number of bound changes */){assert(bdchginds != NULL);assert(bdchgtypes != NULL);assert(bdchgbounds != NULL);assert(nbdchgs != NULL);static void freeBdchgs(SCIP *scip, int **bdchginds, SCIP_BOUNDTYPE **bdchgtypes, SCIP_Real **bdchgbounds, int *nbdchgs)Definition: branch_relpscost.c:705All global functions start with "SCIP". In the usual naming scheme this is followed by the object and a method name like in SCIPlpAddRow(). Functions return TRUE or FALSE should be named like SCIPisFeasEQ().
/** checks if relative difference of val1 and val2 is not lower than -sumepsilon */SCIP_EXPORTSCIP_Real val1, /**< first value to be compared */SCIP_Real val2 /**< second value to be compared */);/** converts the given real number representing an integer to an int; in optimized mode the function gets inlined for* performance; in debug mode we check some additional conditions*/SCIP_EXPORTint SCIPconvertRealToInt();SCIP_Bool SCIPisSumRelGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)Definition: scip_numerics.c:1264int SCIPconvertRealToInt(SCIP *scip, SCIP_Real real)Definition: scip_numerics.c:1279- For each structure there is a typedef with the name in all upper case.
Defines should be named all upper case.
#ifdef __cplusplusextern "C" {#endif/** SCIP operation stage */enum SCIP_Stage{SCIP_STAGE_INIT = 0, /**< SCIP data structures are initialized, no problem exists */SCIP_STAGE_PROBLEM = 1, /**< the problem is being created and modified */SCIP_STAGE_TRANSFORMING = 2, /**< the problem is being transformed into solving data space */SCIP_STAGE_TRANSFORMED = 3, /**< the problem was transformed into solving data space */SCIP_STAGE_INITPRESOLVE = 4, /**< presolving is initialized */SCIP_STAGE_PRESOLVING = 5, /**< the problem is being presolved */SCIP_STAGE_EXITPRESOLVE = 6, /**< presolving is exited */SCIP_STAGE_PRESOLVED = 7, /**< the problem was presolved */SCIP_STAGE_INITSOLVE = 8, /**< the solving process data is being initialized */SCIP_STAGE_SOLVING = 9, /**< the problem is being solved */SCIP_STAGE_SOLVED = 10, /**< the problem was solved */SCIP_STAGE_EXITSOLVE = 11, /**< the solving process data is being freed */SCIP_STAGE_FREETRANS = 12, /**< the transformed problem is being freed */SCIP_STAGE_FREE = 13 /**< SCIP data structures are being freed */};/** possible settings for enabling/disabling algorithms and other features */enum SCIP_Setting{SCIP_UNDEFINED = 0, /**< undefined setting */SCIP_DISABLED = 1, /**< feature is disabled */SCIP_AUTO = 2, /**< feature is set to automatic mode */SCIP_ENABLED = 3 /**< feature is enabled */};#ifdef __cplusplus}#endifDefinition: struct_set.h:75
Documentation:
- Document functions, parameters, and variables in a doxygen conformed way.
- Please do not leave code in comments that has been commented out, don't use
#if 0. Instead put the code within defines#ifdef SCIP_DISABLED_CODEand add an explanation. - Todos need double stars to be registered by doxygen.
When documenting methods, the first brief description starts with lower case and is separated by semi-colons, if necessary The longer description starts capitalized and consists of complete sentences. If the documentation consists of multiple lines, the comment end must be on a new line.
/** copies directed graph structure** The copying procedure uses the memory of the passed SCIP instance. The user must ensure that the digraph lives* as most as long as the SCIP instance.** @note The data in nodedata is copied verbatim. This possibly has to be adapted by the user.*/SCIP_EXPORTSCIP_DIGRAPH** targetdigraph, /**< pointer to store the copied directed graph */SCIP_DIGRAPH* sourcedigraph /**< source directed graph */);SCIP_RETCODE SCIPcopyDigraph(SCIP *scip, SCIP_DIGRAPH **targetdigraph, SCIP_DIGRAPH *sourcedigraph)Definition: scip_datastructures.c:638Definition: struct_misc.h:221
Customize (x)emacs
If you are using (x)emacs, you can use the following customization for the c++-mode. These settings satisfy the coding guidelines of SCIP.
Customize eclipse
Eclipse user can use the profile below. This profile does not match the SCIP coding guideline completely.