一、build and run CPLEX里面自带的例子
二、创建c++项目并连接CPLEX
一
Building and Running CPLEX Examples
The C and C++ CPLEX examples have all been gathered in one project for each type of static format (mta
and mda
). The instructions below use the mta
format for the Visual Studio 2008 environment, but similar instructions apply when using the project file for another format or with Visual Studio 2010. The related file for the mda
format is <CPLEXDIR>\examples\x86_windows_vs2008\stat_mda\examples.sln
. (这里的CPLEXDIR指你的CPLEX安装路径,比如我的就是“C:\Program Files (x86)\IBM\ILOG\CPLEX_Studio125\cplex”,然后加上后面的\examples\...就可以了)
Be aware that the order of the instructions below is important.
- Start Microsoft Visual Studio 2008.
- From the File menu, choose Open Project/Solution.
The Open Project dialog box appears.- Select the folder
<CPLEXDIR>\examples\x86_windows_vs2008\stat_mta
. - Select the
examples.sln
file and click Open.
- Select the folder
- To build only one example (for instance,
blend
):- Select the
blend
project in the Solution Explorer window. - From the Build menu, choose Build blend.
Wait for the completion of the building process.
- Select the
- To build all of the examples:
- From the Build menu, choose Build Solution
Wait for the completion of the building process.
- From the Build menu, choose Build Solution
- To run an example (for instance,
blend
): - Open a command prompt window by running the Visual Studio 2008 Command Prompt.
In the window Visual Studio 2008 Command prompt: - Type
set path=%path%;<CPLEXDIR>\bin\x86_win32
so thatcplex123.dll
is on the path. (这条写的太坑爹,让我试了几十次终于才成功,如果你的CPLEX和我一样安装在默认目录即C:\Program Files x86\...那么就有可能遇到我的问题。这里设置路径的正确指令应该是:set path=C:\Program Files (x86)\IBM\ILOG\CPLEX_Studio125\cplex\bin\x86_win32; 这里面的CPLEX_Studio125指我安装的版本是12.5,如果你的不是正式版的可能不一样,还有我安装的32位因此在Program Files (x86)目录下,如果64位可能会是Program Files目录下) - Type
<CPLEXDIR>\examples\x86_windows_vs2008\stat_mta\blend
. (这里也比较坑爹,如果你和我一样安装在默认目录即C:\Program Files (x86)\下,很可能输入这条指令会显示“‘C:\Program' 不是内部或外部命令,也不是可运行的程序或批处理文件”的错误,那是因为这里系统读到空格处即Program后面就自动断点了,因此,你需要把你的路径用双引号引起来,如"C:\Program Files (x86)\IBM\ILOG\CPLEX_Studio125\cplex\bin\x86_windows_vs2010\stat_mta\blend". 这里x86_windows_vs2010是指你安装的c++版本号,我的是2010.) - The result is then displayed. The setting of the
path
environment variable is only necessary if the this folder is not already on thepath
. The default installer action is to modify the path to include this folder。
注意了上面的问题,你就可以执行任何自带的例子然后看到结果了。
二
Building Your Own Project which Links with CPLEX
Note:The information below applies to the Visual C++ 2008 multi-threaded STL library. If you use another version of the library, set the Runtime Library option to match the library version. If you use Visual Studio 2010, the instructions below should apply, except that
x86_windows_vs2008
should be replaced with x86_windows_vs2010
whenever a path name is specified.
Let's assume that you want to build a target named
test.exe
and have:- a source file named
test.cpp
which uses Concert Technology ortest.c
which uses the C API of the CPLEX Callable Library; - a folder where this file is located and which, for the sake of simplicity, we'll refer to as
<MYAPPDIR>
.
One way to achieve that is to create a project named
test.vcproj
as described here. Be aware that the order of instructions is important. Note that project files for VS2010 have the extension vcxproj
.- Start Microsoft Visual Studio 2008.
- The first step is to build the
test.sln
solution.
From the File menu, select New->, and then Project....
The New Project dialog box appears.
- In the Project types pane, select Visual C++ and Win32.
- In the Templates pane, select the Win32 Console Application icon.
- Fill in the project name (
test
). - If necessary, correct the location of the project (to
<MYAPPDIR>
) - Click OK
When the Win32 Application Wizard appears... - Click on Application Settings.
- Select Console Application as Application type.
- Make sure that Empty project is checked in Additional Options.
- Click Finish.
- Now you must add your source file to the project. From the Project menu, choose Add Existing Item...
- Move to the folder
<MYAPPDIR>
and selecttest.cpp
ortest.c
. - Click Open.
- Move to the folder
- Next, you have to set some options so that the project knows where to find the CPLEX and Concert include files and the CPLEX and Concert libraries.
From the Project menu, choose Properties.
The test Property Pages dialog box appears.
In the Configuration drop-down list, select Release.
Select C/C++ in the Configuration Properties tree.
- Select General:
- In the Additional Include Directories field, add the directories:
<CPLEXDIR>\include
.<CONCERTDIR>\include
.
- For Debug Information Format, choose Disabled (/Zd).
- Choose No for Detect 64-bit Portability Issues. Note that these settings are not available in the Visual Studio 2010 IDE and can be omitted.
- In the Additional Include Directories field, add the directories:
- Select Preprocessor:
- Add
IL_STD
to the Preprocessor Definitions field. This defines the macro IL_STD which is needed to use the STL.
- Add
- Select Code Generation:
- Set Runtime Library to Multi-threaded (/MT).
- Select General and then select Additional Library Directoriess. Add the files:
<CPLEXDIR>\lib\x86_windows_vs2008\stat_mta
<CONCERTDIR>\lib\x86_windows_vs2008\stat_mta
- Select Input and then select Additional Dependencies. Add the files:
cplex123.lib
ilocplex.lib
concert.lib
- Select General:
- Next, you have to set the default project configuration.From the Build menu, select Configuration Manager...
- Select Release in the Active Solution Configuration drop-down list.
- Click Close.
- Finally, to build the project, from the Build menu, select Build Solution
test
, with a single project, test
. You can see the contents of the solution by selecting Solution Explorer in the View menu.test.exe
is <MYAPPDIR>\test\Release\test.exe
.Remark:
From the Concert point of view, the only difference between the Win32 Release and Win32 Debug targets is:
- the
NDEBUG
macro is defined for the Win32 Release target. - the
NDEBUG
macro is not defined for the Win32 Debug target.
The interaction of the
NDEBUG
macro and the Concert inline member functions is documented in the Concepts section of the CPLEX C++ API Reference Manual. R
没有评论:
发表评论