How to call function from external library in C/C++

前端 未结 1 1798
北恋
北恋 2021-01-27 00:04

I want to find the symmetry group of an integer linear program. I think there is a function in skip called SCIPgetGeneratorsSymmetry . I how I can use this function?

1条回答
  •  孤独总比滥情好
    2021-01-27 00:38

    You are right, to access symmetry information in SCIP, you have to call the function SCIPgetGeneratorsSymmetry() via C/C++. Note that you need to link SCIP against the external software bliss, because otherwise, SCIP is not able to compute symmetries of your (mixed-integer) linear program.

    If you set up your (mixed-integer) linear program using a C/C++ project, you have several options for computing symmetries.

    • If you set the "recompute" parameter to FALSE, SCIP will return the currently available symmetry information - if symmetries have not been computed yet, SCIP will compute symmetries to give you access to this information.

    • If you set "recompute" to TRUE, SCIP will discard the available symmetry information and you get access to the generators of the current symmetry group. Moreover, you can control the kind of symmetries that are computed via the parameters "symspecrequire" and "symspecrequirefixed", e.g., to only compute symmetries of binary variables that fix continuous variables.

    Edit:

    If you have no experience with coding in C/C++ and you are only interested in printing the generators of the symmetry group, the easiest way is probably to modify SCIP's source code in presol_symmetry.c as follows:

    • Add two integer paramaters int i and int p at the very beginning of determineSymmetry().
    • Search within determineSymmetry() for the line in which computeSymmetryGroup() is called.

    • Add the following code snippet right after this function call:

    for (p = 0; p < presoldata->nperms; ++p)
    {
        printf("permutation %d\n", p);
        for (i = 0; i < presoldata->npermvars; ++i)
        {
           if ( TRUE )
              printf("%d ", presoldata->perms[p][i]);
           else
              printf("%s ", SCIPvarGetName(presoldata->permvars[presoldata->perms[p][i]]));
        }
        printf("\n");
    }
    
    • This code prints the generators of the symmetry group as a list of variable indices, e.g., 1 2 0 is the permutation that maps 0 -> 1, 1 -> 2, and 2 -> 0. If you change TRUE to FALSE, you get the same list but variable indices are replaced by their names.
    • Do not forget to recompile SCIP.
    • If you solve an instance with SCIP and symmetry handling is enabled, SCIP will print the generators in the above format whenever it computes the symmetry group. If you are interested in the symmetry group of the original problem, you should use the parameter setting presolving/symbreak/addconsstiming = 0 and propagating/orbitalfixing/symcomptiming = 0. If you are fine with symmetries of the presolved problem, change the zeros to ones.

    0 讨论(0)
提交回复
热议问题