如何在C/C ++中从外部库调用函数 [英] How to call function from external library in C/C++

查看:330
本文介绍了如何在C/C ++中从外部库调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到一个整数线性程序的对称组.我认为Skip中有一个名为SCIPgetGeneratorsSymmetry的函数.我该如何使用此功能?

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?

推荐答案

是的,要访问SCIP中的对称信息,您必须通过C/C ++调用函数SCIPgetGeneratorsSymmetry().请注意,您需要将SCIP与外部软件联系起来,否则SCIP将无法计算(混合整数)线性程序的对称性.

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.

如果使用C/C ++项目设置(混合整数)线性程序,则可以使用多个选项来计算对称性.

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

  • 如果将"recompute"参数设置为FALSE,则SCIP将返回当前可用的对称性信息-如果尚未计算对称性,SCIP将计算对称性以使您可以访问此信息.

  • 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.

如果将"recompute"设置为TRUE,SCIP将丢弃可用的对称性信息,并且可以访问当前对称性组的生成器.此外,您可以控制通过参数"symspecrequire"和"symspecrequirefixed"计算的对称类型,例如,仅计算固定连续变量的二进制变量的对称性.

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.

如果您没有使用C/C ++进行编码的经验,并且只对打印对称组的生成器感兴趣,那么最简单的方法可能是在presol_symmetry.c中修改SCIP的源代码,如下所示:

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:

  • determineSymmetry()的开始处添加两个整数参数int iint p.
  • determineSymmetry()中搜索调用computeSymmetryGroup()的行.

  • 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");
}

  • 此代码将对称组的生成器打印为变量索引列表,例如1 2 0是映射0-> 1、1-> 2和2-> 0的置换.如果更改FALSE,您将获得相同的列表,但变量索引将被其名称替换.
  • 不要忘记重新编译SCIP.
  • 如果使用SCIP解决实例并且启用了对称处理,则SCIP在计算对称组时将以上述格式打印生成器.如果对原始问题的对称性组感兴趣,则应使用参数设置presolving/symbreak/addconsstiming = 0propagating/orbitalfixing/symcomptiming = 0.如果对已解决问题的对称性满意,请将零更改为1.
    • 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.
    • 这篇关于如何在C/C ++中从外部库调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆