Gurobi8.0.1+VisualStudio2015

1. Download Gurobi from address:http://www.gurobi.com/

2.Install and get license under campus network, and you can finish it according to homepage of Gurobi.

3.Configure Gurobi library on the VS2015

3.1.Add include directories and library directories to [Property Pages] of VS2015

3.2 Add additional dependencies to VS2015, according to [C/C++|Code Generation|Runtime Library].

Note: You must add gurobi80.lib.

3.3 Test source

/* Copyright 2018, Gurobi Optimization, LLC */

/* This example formulates and solves the following simple QCP model:

maximize    x
subject to  x + y + z = 1
x^2 + y^2 <= z^2 (second-order cone)
x^2 <= yz        (rotated second-order cone)
*/

#include "gurobi_c++.h"
using namespace std;

int main( )
{
	try {
		GRBEnv env = GRBEnv();

		GRBModel model = GRBModel(env);

		// Create variables

		GRBVar x = model.addVar(0.0, GRB_INFINITY, 0.0, GRB_CONTINUOUS, "x");
		GRBVar y = model.addVar(0.0, GRB_INFINITY, 0.0, GRB_CONTINUOUS, "y");
		GRBVar z = model.addVar(0.0, GRB_INFINITY, 0.0, GRB_CONTINUOUS, "z");

		// Set objective

		GRBLinExpr obj = x;
		model.setObjective(obj, GRB_MAXIMIZE);

		// Add linear constraint: x + y + z = 1

		model.addConstr(x + y + z == 1, "c0");

		// Add second-order cone: x^2 + y^2 <= z^2

		model.addQConstr(x*x + y*y <= z*z, "qc0");

		// Add rotated cone: x^2 <= yz

		model.addQConstr(x*x <= y*z, "qc1");

		// Optimize model

		model.optimize();

		cout << x.get(GRB_StringAttr_VarName) << " "
			<< x.get(GRB_DoubleAttr_X) << endl;
		cout << y.get(GRB_StringAttr_VarName) << " "
			<< y.get(GRB_DoubleAttr_X) << endl;
		cout << z.get(GRB_StringAttr_VarName) << " "
			<< z.get(GRB_DoubleAttr_X) << endl;

		cout << "Obj: " << model.get(GRB_DoubleAttr_ObjVal) << endl;

	}
	catch (GRBException e) {
		cout << "Error code = " << e.getErrorCode() << endl;
		cout << e.getMessage() << endl;
	}
	catch (...) {
		cout << "Exception during optimization" << endl;
	}

	return 0;
}

Success!

4.May you succeed!! 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值