首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于scip优化的lapack库

用于scip优化的lapack库
EN

Stack Overflow用户
提问于 2014-11-17 15:10:24
回答 2查看 610关注 0票数 1

我有一个带线性约束的二次优化问题,我想用SCIP来解决。我想要最小化的优化矩阵是正半定(准确地说是某些变量的方差)。我在CPLEX LP格式的文件中遇到了问题,当我在SCIP中进行优化时,我得到了消息

代码语言:javascript
复制
Quadratic constraint handler does not have LAPACK for eigenvalue computation. Will assume
that matrices (with size > 2x2) are indefinite.

因此,假设矩阵是不确定的,并且需要大量时间,SCIP就开始进行优化。我已经安装了LAPACK,甚至在lib文件夹中复制了SCIP文件,其中SCIP源代码和二进制文件被安装并重新安装了SCIP。但是,我一直收到上面的信息。

有办法让SCIP使用LAPACK库吗?我相信,如果SCIP能计算出矩阵是半正定的,那么优化将会是非常快的。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-11-17 15:42:28

如果您想在不提供完整Ipopt的情况下修补SCIP以使用Lapack lib (尽管在*nix上构建比较容易,并且可以帮助性能,正如mattmilten指出的那样),下面是您可以尝试的修补程序:

代码语言:javascript
复制
diff --git a/src/scip/cons_quadratic.c b/src/scip/cons_quadratic.c
index 93ba359..795bade 100644
--- a/src/scip/cons_quadratic.c
+++ b/src/scip/cons_quadratic.c
@@ -46,7 +46,7 @@
 #include "scip/heur_trysol.h"
 #include "scip/debug.h"
 #include "nlpi/nlpi.h"
-#include "nlpi/nlpi_ipopt.h"
+/*#include "nlpi/nlpi_ipopt.h" */

 /* constraint handler properties */
 #define CONSHDLR_NAME          "quadratic"
@@ -4257,6 +4257,71 @@ void checkCurvatureEasy(
       *determined = FALSE;
 }

+#define F77_FUNC(a,A) a##_
+
+   /** LAPACK Fortran subroutine DSYEV */
+   void F77_FUNC(dsyev,DSYEV)(
+      char*                 jobz,               /**< 'N' to compute eigenvalues only, 'V' to compute eigenvalues and eigenvectors */
+      char*                 uplo,               /**< 'U' if upper triangle of A is stored, 'L' if lower triangle of A is stored */
+      int*                  n,                  /**< dimension */
+      double*               A,                  /**< matrix A on entry; orthonormal eigenvectors on exit, if jobz == 'V' and info == 0; if jobz == 'N', then the matrix data is destroyed */
+      int*                  ldA,                /**< leading dimension, probably equal to n */
+      double*               W,                  /**< buffer for the eigenvalues in ascending order */
+      double*               WORK,               /**< workspace array */
+      int*                  LWORK,              /**< length of WORK; if LWORK = -1, then the optimal workspace size is calculated and returned in WORK(1) */
+      int*                  info                /**< == 0: successful exit; < 0: illegal argument at given position; > 0: failed to converge */
+      );
+
+/** Calls Lapacks Dsyev routine to compute eigenvalues and eigenvectors of a dense matrix. 
+ */
+static
+SCIP_RETCODE LapackDsyev(
+   SCIP_Bool             computeeigenvectors,/**< should also eigenvectors should be computed ? */
+   int                   N,                  /**< dimension */
+   SCIP_Real*            a,                  /**< matrix data on input (size N*N); eigenvectors on output if computeeigenvectors == TRUE */
+   SCIP_Real*            w                   /**< buffer to store eigenvalues (size N) */
+   )
+{
+   int     INFO;
+   char    JOBZ = computeeigenvectors ? 'V' : 'N';
+   char    UPLO = 'L';
+   int     LDA  = N;
+   double* WORK = NULL;
+   int     LWORK;
+   double  WORK_PROBE;
+   int     i;
+
+   /* First we find out how large LWORK should be */
+   LWORK = -1;
+   F77_FUNC(dsyev,DSYEV)(&JOBZ, &UPLO, &N, a, &LDA, w, &WORK_PROBE, &LWORK, &INFO);
+   if( INFO != 0 )
+   {
+      SCIPerrorMessage("There was an error when calling DSYEV. INFO = %d\n", INFO);
+      return SCIP_ERROR;
+   }
+
+   LWORK = (int) WORK_PROBE;
+   assert(LWORK > 0);
+
+   SCIP_ALLOC( BMSallocMemoryArray(&WORK, LWORK) );
+
+   for( i = 0; i < LWORK; ++i )
+      WORK[i] = i;
+
+   F77_FUNC(dsyev,DSYEV)(&JOBZ, &UPLO, &N, a, &LDA, w, WORK, &LWORK, &INFO);
+
+   BMSfreeMemoryArray(&WORK);
+
+   if( INFO != 0 )
+   {
+      SCIPerrorMessage("There was an error when calling DSYEV. INFO = %d\n", INFO);
+      return SCIP_ERROR;
+   }
+
+   return SCIP_OKAY;
+}
+
+
 /** checks a quadratic constraint for convexity and/or concavity */
 static
 SCIP_RETCODE checkCurvature(
@@ -4343,7 +4408,7 @@ SCIP_RETCODE checkCurvature(
       return SCIP_OKAY;
    }

-   if( SCIPisIpoptAvailableIpopt() )
+   if( TRUE )
    {
       for( i = 0; i < consdata->nbilinterms; ++i )
       {
@@ -4479,7 +4544,7 @@ SCIP_RETCODE checkFactorable(
       return SCIP_OKAY;

    /* need routine to compute eigenvalues/eigenvectors */
-   if( !SCIPisIpoptAvailableIpopt() )
+   if( !TRUE )
       return SCIP_OKAY;

    SCIP_CALL( consdataSortQuadVarTerms(scip, consdata) );
@@ -9395,7 +9460,7 @@ SCIP_DECL_CONSINITSOL(consInitsolQuadratic)
       SCIP_CALL( SCIPcatchEvent(scip, SCIP_EVENTTYPE_SOLFOUND, eventhdlr, (SCIP_EVENTDATA*)conshdlr, &conshdlrdata->newsoleventfilterpos) );
    }

-   if( nconss != 0 && !SCIPisIpoptAvailableIpopt() && !SCIPisInRestart(scip) )
+   if( nconss != 0 && !TRUE && !SCIPisInRestart(scip) )
    {
       SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, "Quadratic constraint handler does not have LAPACK for eigenvalue computation. Will assume that matrices (with size > 2x2) are indefinite.\n");
    }

在make中使用USRLDFLAGS="-llapack -lblas"

票数 4
EN

Stack Overflow用户

发布于 2014-11-17 15:32:51

目前,SCIP只能通过伊波普使用LAPACK。在使用Ipopt支持编译SCIP时,通常对非线性问题有更好的性能,因此建议采用这种方法。跑

代码语言:javascript
复制
make IPOPT=true

确保你事先安装了Ipopt。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26975673

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档