死磕Mosek!新mosek学习笔记1:VS项目配置。

啥也不说了,我就跟Mosek死磕了,从头开始学 MOSEK Optimizer API for C 9.1.13。英文原文:

  1. Create a project or open an existing project in Visual Studio.
  2. In the Solution Explorer right-click on the relevant project and select Properties. This will open the Property pages dialog.
  3. In the selection box Configuration: select All Configurations.
  4. In the tree-view open Configuration Properties → C/C++ → General.
  5. In the properties click the Additional Include Directories field and select edit.
  6. Click on the New Folder button and write the full path to the h header file or browse for the file. For example, for 64-bit Windows use <HEADERDIR>.
  7. Click OK.
  8. Back in the Property Pages dialog select from the tree-view Configuration Properties → Linker → Input.
  9. In the properties,view click in the Additional Dependencies field and select edit. This will open the Additional Dependencies dialog.
  10. Add the full path of the MOSEK lib. For example, for 64-bit Windows:
  11. <LIBDIR> \ mosek64_9_1.lib
  12. Click OK.
  13. Back in the Property Pages dialog click OK.

其实基本就是配置两条,

一个在C/C++选项的General,配置下路径..\Mosek\9.1\tools\platform\win64x86\h; link:..\Mosek\9.1\tools\platform\win64x86\bin\mosek64_9_1.lib

Hello World实验程序。这里的配置要比Fusion容易。

#include "mosek.h"
#include <stdio.h>

/* Error checking not included */
int main() {
    MSKrescodee      r, trmcode;
    MSKenv_t         env = NULL;
    MSKtask_t        task = NULL;
    double           xx = 0.0;

    MSK_makeenv(&env, NULL);             // Create environment
    MSK_maketask(env, 0, 1, &task);      // Create task

    MSK_appendvars(task, 1);                             // 1 variable x
    MSK_putcj(task, 0, 1.0);                             // c_0 = 1.0
    MSK_putvarbound(task, 0, MSK_BK_RA, 2.0, 3.0);       // 2.0 <= x <= 3.0
    MSK_putobjsense(task, MSK_OBJECTIVE_SENSE_MINIMIZE); // Minimize

    MSK_optimizetrm(task, &trmcode);         // Optimize

    MSK_getxx(task, MSK_SOL_ITR, &xx);       // Get solution
    printf("Solution x = %f\n", xx);         // Print solution

    MSK_deletetask(&task); // Clean up task
    MSK_deleteenv(&env);   // Clean up environment
    return 0;
}

观察了这个源代码,觉得在方法实现形式上比Fusion上容易。基本上是传统的编程方法。

下面就是来看一下这个具体怎么来玩。

学习笔记2:设计框架 https://blog.csdn.net/aliexken/article/details/104575835

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序猿老甘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值