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

自闭症网瘾萝莉.ら 提交于 2020-03-12 05:29:27

问题


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:


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.


来源:https://stackoverflow.com/questions/60048756/how-to-call-function-from-external-library-in-c-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!