Skip to content

Instantly share code, notes, and snippets.

@msakai
Last active May 29, 2016 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msakai/c0b5682c73859f72c2368c7317c6f78c to your computer and use it in GitHub Desktop.
Save msakai/c0b5682c73859f72c2368c7317c6f78c to your computer and use it in GitHub Desktop.
$ cat primer.cpp
#include <cmip.h>
#include <except.h>
#include <iostream>
int variant1()
{
try {
CMIP prob("MIPCLtest"); // 1
prob.openMatrix(2,2,4); // 2
prob.addVar(0,CMIP::VAR_INT, 100.0,0.0, CLP::VAR_INF); // 3
prob.addVar(1,CMIP::VAR_INT, 64.0,0.0, CLP::VAR_INF); // 4
prob.addCtr(0,0,-CLP::INF,250); // 5
prob.addCtr(1,0,-CLP::INF,4); // 6
prob.addEntry(50.0,0,0); // 7.1
prob.addEntry(31.0,0,1); // 7.2
prob.addEntry(-3.0,1,0); // 7.3
prob.addEntry( 2.0,1,1); // 7.4
prob.closeMatrix(); // (8)
prob.optimize(); // (9)
prob.printSolution("primer.sol"); // (10)
}
catch(CException* pe) {
std::cerr << pe->getErrorMessage() << std::endl;
delete pe;
return 1;
}
return 0;
} // end of variant1
// Constants that represent our test IP.
const int n=2, m=2, nz=4;
double c[] = {100,64}; // cost vector
double A[][n] = { // matrix
{50,31},
{-3,2}
};
double b[] = {250,4}; // right-hand side vector
int ind[] = {0,1}; // array of indices
int variant2()
{
try {
CMIP prob("MIPCLtest"); // create new MIP problem
prob.openMatrix(n,m,nz); // open matrix
for (int j=0; j < n; ++j) // adds n variables:
prob.addVar(j,CMIP::VAR_INT, c[j],0.0, CLP::VAR_INF);
for (int i=0; i < m; ++i) // add m rows (constraints):
prob.addRow(i,0,-CLP::INF,b[i],n,A[i],ind);
prob.closeMatrix(); // close matrix
prob.optimize(); // solve problem
prob.printSolution("primer.sol"); // print solution
}
catch(CException* pe) {
std::cerr << pe->getErrorMessage() << std::endl;
delete pe;
return 1;
}
return 0;
} // end of variant2
int main(int argc, char *argv[])
{
return (argv[1][0] == '1')? variant1(): variant2();
}
$ g++ -c -I/usr/local/mipcl-1.1.2/mipcl/headers -m64 -DMIP_API= primer.cpp
$ g++ primer.o -L/usr/local/mipcl-1.1.2/lib -lmipcl -o primer
$ ./primer 1
Start preprocessing: Rows - 2, Cols - 2 (Int - 2, Bin - 0), NZs - 4
==================================== Probing =====================================
Time Round Probed vars Fixed vars Mod. entries New var bds Implications
0.003 1 2 0 0 0 0
==================================================================================
After preprocessing: Rows - 2, Cols - 2 (Int - 2, Bin - 0), NZs - 4
Scaling...
Max exp = 1
Preprocessing Time: 0.003
Optimizing...
0.003 1 0 D/S 508.0000
Generating cuts...
Time Obj Frac vars Cuts
0.003 508.0000 1 1
0.004 505.2632 2 2
Cut statistics
========== Cuts = Generated === Used
dense Gomory 3 2
========= total 3 2
===========================================
MIPCL version 1.1.0
Solution time: 0.004
Branch-and-Cut nodes: 1
Objective value: 500.0000 - optimality proven
*** stack smashing detected ***: ./primer terminated
Aborted (core dumped)
$ ldd primer
linux-vdso.so.1 => (0x00007ffd29f61000)
libmipcl.so => /usr/local/mipcl-1.1.2/lib/libmipcl.so (0x00007f05a07b2000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f05a0427000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f05a0210000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f059fe47000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f059fc2a000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f059f920000)
/lib64/ld-linux-x86-64.so.2 (0x00005596236f1000)
$ g++ --version
g++ (Ubuntu 5.3.1-14ubuntu2) 5.3.1 20160413
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ uname -a
Linux ubuntu-1gb-sfo1-01 4.4.0-22-generic #40-Ubuntu SMP Thu May 12 22:03:46 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment