genmodel 0.0.20 → 0.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/ext/Genmodel/GenModel.h +152 -0
- data/ext/Genmodel/GenModelBase.cpp +389 -0
- data/ext/Genmodel/GenModelCplex.cpp +814 -0
- data/ext/Genmodel/GenModelCplex.h +85 -0
- data/ext/Genmodel/GenModelOsi.cpp +892 -0
- data/ext/Genmodel/GenModelOsi.h +96 -0
- data/ext/Genmodel/GenModelOsiInterface.cpp +143 -0
- data/ext/Genmodel/GenModelOsiInterface.h +43 -0
- data/ext/Genmodel/Genmodel.cpp +10789 -0
- data/ext/Genmodel/InterfaceObject.cpp +68 -0
- data/ext/Genmodel/InterfaceObject.h +28 -0
- data/ext/Genmodel/ProblemReaderOsi.cpp +78 -0
- data/ext/Genmodel/ProblemReaderOsi.h +31 -0
- data/ext/Genmodel/extconf.rb +162 -0
- data/lib/Genmodel.rb +5 -0
- metadata +25 -13
- data/lib/genmodel.bundle +0 -0
- data/lib/genmodel.so +0 -0
@@ -0,0 +1,68 @@
|
|
1
|
+
//
|
2
|
+
// InterfaceObject.cpp
|
3
|
+
//
|
4
|
+
//
|
5
|
+
// Created by Mathieu Bouchard on 2014-03-19.
|
6
|
+
//
|
7
|
+
//
|
8
|
+
|
9
|
+
#include "InterfaceObject.h"
|
10
|
+
|
11
|
+
template<class T> InterfaceVector<T>::InterfaceVector()
|
12
|
+
{
|
13
|
+
val = NULL;
|
14
|
+
size = 0;
|
15
|
+
//printf("\tC++: Adress at creation is %p size = %d\n", val, size);
|
16
|
+
}
|
17
|
+
|
18
|
+
template<class T> InterfaceVector<T>::InterfaceVector(int _size)
|
19
|
+
{
|
20
|
+
size = _size;
|
21
|
+
val = new T[size];
|
22
|
+
//printf("\tC++: Adress at creation is %p size = %d\n", val, size);
|
23
|
+
//memset(val, 0, sizeof(T));
|
24
|
+
}
|
25
|
+
|
26
|
+
template<class T> InterfaceVector<T>::~InterfaceVector()
|
27
|
+
{
|
28
|
+
Delete();
|
29
|
+
}
|
30
|
+
|
31
|
+
template<class T> void InterfaceVector<T>::SetSize(int _size)
|
32
|
+
{
|
33
|
+
Delete();
|
34
|
+
size = _size;
|
35
|
+
val = new T[size];
|
36
|
+
}
|
37
|
+
template<class T> void InterfaceVector<T>::Delete()
|
38
|
+
{
|
39
|
+
size = 0;
|
40
|
+
if(val != NULL)
|
41
|
+
delete[] val;
|
42
|
+
}
|
43
|
+
|
44
|
+
template<class T> void InterfaceVector<T>::Set(int index, T inval)
|
45
|
+
{
|
46
|
+
if(index < 0 || index >= size)
|
47
|
+
printf("Index out of bound (%d not in 0..%d)\n", index, size);
|
48
|
+
else
|
49
|
+
val[index] = inval;
|
50
|
+
}
|
51
|
+
|
52
|
+
template<class T> T InterfaceVector<T>::Get(int index)
|
53
|
+
{
|
54
|
+
if(index < 0 || index >= size)
|
55
|
+
printf("Index out of bound (%d not in 0..%d)\n", index, size);
|
56
|
+
else
|
57
|
+
return val[index];
|
58
|
+
return 0.0;
|
59
|
+
}
|
60
|
+
|
61
|
+
template<class T> T* InterfaceVector<T>::Ptr()
|
62
|
+
{
|
63
|
+
return val;
|
64
|
+
}
|
65
|
+
|
66
|
+
template class InterfaceVector<int>;
|
67
|
+
template class InterfaceVector<long>;
|
68
|
+
template class InterfaceVector<double>;
|
@@ -0,0 +1,28 @@
|
|
1
|
+
//
|
2
|
+
// InterfaceObject.h
|
3
|
+
//
|
4
|
+
//
|
5
|
+
// Created by Mathieu Bouchard on 2014-03-19.
|
6
|
+
//
|
7
|
+
//
|
8
|
+
|
9
|
+
#ifndef _InterfaceObject_h
|
10
|
+
#define _InterfaceObject_h
|
11
|
+
|
12
|
+
template<class T> class InterfaceVector {
|
13
|
+
public:
|
14
|
+
InterfaceVector();
|
15
|
+
InterfaceVector(int size);
|
16
|
+
~InterfaceVector();
|
17
|
+
void SetSize(int size);
|
18
|
+
void Delete();
|
19
|
+
void Set(int index, T val);
|
20
|
+
T Get(int index);
|
21
|
+
T* Ptr();
|
22
|
+
|
23
|
+
private:
|
24
|
+
int size;
|
25
|
+
T * val;
|
26
|
+
};
|
27
|
+
|
28
|
+
#endif
|
@@ -0,0 +1,78 @@
|
|
1
|
+
/*
|
2
|
+
* ProblemReaderOsi.cpp
|
3
|
+
*
|
4
|
+
* Created on: 2012-10-02
|
5
|
+
* Author: mbouchard
|
6
|
+
*/
|
7
|
+
|
8
|
+
#include "ProblemReaderOsi.h"
|
9
|
+
|
10
|
+
int ReadFromFile(GenModel* pgm, string fn, int type, string dn)
|
11
|
+
{
|
12
|
+
OsiSolverInterface* pm = new OsiClpSolverInterface();
|
13
|
+
//OsiSolverInterface* pm = new OsiGlpkSolverInterface();
|
14
|
+
|
15
|
+
switch (type)
|
16
|
+
{
|
17
|
+
case 0: pm->readMps(fn.c_str()); break;
|
18
|
+
case 1: pm->readLp(fn.c_str()); break;
|
19
|
+
case 2: pm->readGMPL(fn.c_str(), (dn == "" ? NULL : dn.c_str())); break;
|
20
|
+
default: pm->readMps(fn.c_str()); break;
|
21
|
+
}
|
22
|
+
|
23
|
+
return ReadFromObject(pgm, pm);
|
24
|
+
}
|
25
|
+
|
26
|
+
int ReadFromObject(GenModel* pgm, OsiSolverInterface* pm)
|
27
|
+
{
|
28
|
+
char tmp[64];
|
29
|
+
int numr = pm->getNumRows();
|
30
|
+
int numc = pm->getNumCols();
|
31
|
+
pgm->nz = 0;
|
32
|
+
|
33
|
+
const double* obj = pm->getObjCoefficients();
|
34
|
+
const double* lb = pm->getColLower();
|
35
|
+
const double* ub = pm->getColUpper();
|
36
|
+
const char* type = pm->getColType();
|
37
|
+
for(int i = 0; i < numc; i++)
|
38
|
+
{
|
39
|
+
char gmtype;
|
40
|
+
snprintf(tmp,64,"C%d", i);
|
41
|
+
switch (type[i])
|
42
|
+
{
|
43
|
+
case 0: gmtype = 'C'; break;
|
44
|
+
case 1: gmtype = 'B'; break;
|
45
|
+
case 2: gmtype = 'I'; break;
|
46
|
+
default: gmtype = 'C'; break;
|
47
|
+
}
|
48
|
+
pgm->AddVar(string(tmp), obj[i],
|
49
|
+
(lb[i]==COIN_DBL_MAX?numeric_limits<double>::infinity():(lb[i]==-COIN_DBL_MAX?-numeric_limits<double>::infinity():lb[i])),
|
50
|
+
(ub[i]==COIN_DBL_MAX?numeric_limits<double>::infinity():(ub[i]==-COIN_DBL_MAX?-numeric_limits<double>::infinity():ub[i])), gmtype);
|
51
|
+
}
|
52
|
+
const char* sense = pm->getRowSense();
|
53
|
+
const double* lrhs = pm->getRowLower();
|
54
|
+
const double* urhs = pm->getRowUpper();
|
55
|
+
|
56
|
+
const CoinPackedMatrix* pcpm = pm->getMatrixByRow();
|
57
|
+
const double* elem = pcpm->getElements();
|
58
|
+
const int* ind = pcpm->getIndices();
|
59
|
+
|
60
|
+
for(int i = 0; i < numr; i++)
|
61
|
+
{
|
62
|
+
snprintf(tmp,64,"R%d", i);
|
63
|
+
if(sense[i] == 'L')
|
64
|
+
pgm->AddConst(string(tmp),
|
65
|
+
(urhs[i]==COIN_DBL_MAX?numeric_limits<double>::infinity():(urhs[i]==-COIN_DBL_MAX?-numeric_limits<double>::infinity():urhs[i])), sense[i]);
|
66
|
+
else
|
67
|
+
pgm->AddConst(string(tmp),
|
68
|
+
(lrhs[i]==COIN_DBL_MAX?numeric_limits<double>::infinity():(lrhs[i]==-COIN_DBL_MAX?-numeric_limits<double>::infinity():lrhs[i])), sense[i]);
|
69
|
+
pgm->consts.back().urhs = (urhs[i]==COIN_DBL_MAX?numeric_limits<double>::infinity():(urhs[i]==-COIN_DBL_MAX?-numeric_limits<double>::infinity():urhs[i]));
|
70
|
+
//if(fabs(lrhs[i]) > 1e-4 || fabs(urhs[i]) > 1e-4) //What is that ???
|
71
|
+
for(int j = pcpm->getVectorFirst(i); j < pcpm->getVectorLast(i); j++)
|
72
|
+
{
|
73
|
+
pgm->AddNzToLast(ind[j], elem[j]);
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
return 0;
|
78
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
/*
|
2
|
+
* ProblemReaderOsi.h
|
3
|
+
*
|
4
|
+
* Created on: 2012-10-02
|
5
|
+
* Author: mbouchard
|
6
|
+
*/
|
7
|
+
|
8
|
+
#ifndef PROBLEMREADER_H_
|
9
|
+
#define PROBLEMREADER_H_
|
10
|
+
|
11
|
+
#ifndef CBC_THREAD
|
12
|
+
#define CBC_THREAD
|
13
|
+
#endif
|
14
|
+
|
15
|
+
#if defined WIN64 || defined WIN32
|
16
|
+
#ifndef snprintf
|
17
|
+
#define snprintf sprintf_s
|
18
|
+
#endif
|
19
|
+
#endif
|
20
|
+
|
21
|
+
#include "GenModel.h"
|
22
|
+
#include "OsiClpSolverInterface.hpp"
|
23
|
+
//#include "OsiGlpkSolverInterface.hpp"
|
24
|
+
#include <string>
|
25
|
+
|
26
|
+
using namespace std;
|
27
|
+
|
28
|
+
int ReadFromFile(GenModel* pgm, string fn, int type=0, string dn = "");
|
29
|
+
int ReadFromObject(GenModel* pgm, OsiSolverInterface* pm);
|
30
|
+
|
31
|
+
#endif /* PROBLEMREADER_H_ */
|
@@ -0,0 +1,162 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
require 'rbconfig'
|
3
|
+
|
4
|
+
extension_name = 'GenModel/GenModel'
|
5
|
+
dir_config(extension_name)
|
6
|
+
|
7
|
+
#abort "missing malloc()" unless have_func "malloc"
|
8
|
+
#abort "missing free()" unless have_func "free"
|
9
|
+
|
10
|
+
parts = RUBY_DESCRIPTION.split(' ')
|
11
|
+
type = parts[0]
|
12
|
+
type = type[4..-1] if type.start_with?('tcs-')
|
13
|
+
type = 'ree' if 'ruby' == type && RUBY_DESCRIPTION.include?('Ruby Enterprise Edition')
|
14
|
+
is_windows = RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
|
15
|
+
is_linux = RbConfig::CONFIG['host_os'] =~ /(linux)/
|
16
|
+
is_darwin = RbConfig::CONFIG['host_os'] =~ /(darwin??)/
|
17
|
+
platform = RUBY_PLATFORM
|
18
|
+
version = RUBY_VERSION.split('.')
|
19
|
+
|
20
|
+
|
21
|
+
if is_darwin
|
22
|
+
puts "DEFINE Darwin"
|
23
|
+
$defs.push("-DDarwin")
|
24
|
+
elsif is_linux
|
25
|
+
puts "DEFINE Linux"
|
26
|
+
$defs.push("-DLinux")
|
27
|
+
elsif is_windows
|
28
|
+
puts "DEFINE WIN64"
|
29
|
+
$defs.push("-DWIN64")
|
30
|
+
else
|
31
|
+
puts "Unknown platform"
|
32
|
+
$defs.push("-DUnknownPlatform")
|
33
|
+
end
|
34
|
+
puts ">>>>> Creating Makefile for #{type} version #{RUBY_VERSION} on #{platform} (#{RbConfig::CONFIG['host_os']}) <<<<<"
|
35
|
+
|
36
|
+
|
37
|
+
puts "#{CONFIG["dldflags"]}"
|
38
|
+
CONFIG["DLDFLAGS"].gsub!(/-multiply_definedsuppress/, '')
|
39
|
+
$DLDFLAGS = CONFIG["DLDFLAGS"]
|
40
|
+
puts "#{CONFIG["DLDFLAGS"]}, #{$DLDFLAGS}"
|
41
|
+
|
42
|
+
is_cplex = true;
|
43
|
+
is_osi = true;
|
44
|
+
if is_darwin
|
45
|
+
path = CONFIG['HOME']+"/Applications/IBM/ILOG/CPLEX_Studio126/cplex/include:/opt/ibm/ILOG/CPLEX_Studio126/cplex/include"
|
46
|
+
puts "Looking for ilcplex/cplex.h in "+path
|
47
|
+
if(is_cplex && find_header("ilcplex/cplex.h",path))
|
48
|
+
puts "found"
|
49
|
+
else
|
50
|
+
puts "not found"
|
51
|
+
is_cplex = false
|
52
|
+
end
|
53
|
+
|
54
|
+
path = CONFIG['HOME']+"/Applications/IBM/ILOG/CPLEX_Studio126/cplex/lib/x86-64_osx/static_pic"
|
55
|
+
puts "Looking for libcplex (function CPXopenCPLEX) in "+path
|
56
|
+
if(is_cplex && find_header("libcplex","CPXopenCPLEX",path))
|
57
|
+
puts "found"
|
58
|
+
else
|
59
|
+
puts "not found"
|
60
|
+
is_cplex = false
|
61
|
+
end
|
62
|
+
elsif is_linux
|
63
|
+
path = CONFIG['HOME']+"/ibm/ILOG/CPLEX_Studio126/cplex/include:/opt/ibm/ILOG/CPLEX_Studio126/cplex/include"
|
64
|
+
puts "Looking for ilcplex/cplex.h in "+path
|
65
|
+
if(is_cplex && find_header("ilcplex/cplex.h",path))
|
66
|
+
puts "found"
|
67
|
+
else
|
68
|
+
puts "not found"
|
69
|
+
is_cplex = false
|
70
|
+
end
|
71
|
+
|
72
|
+
path = "/usr/lib:/usr/local/lib/"
|
73
|
+
puts "Looking for pthread (function main) in "+path
|
74
|
+
if(find_header("pthread",nil,path))
|
75
|
+
puts "found"
|
76
|
+
else
|
77
|
+
puts "not found"
|
78
|
+
end
|
79
|
+
|
80
|
+
path = "/usr/lib:/usr/local/lib/"
|
81
|
+
puts "Looking for Clp (function main) in "+path
|
82
|
+
if(is_osi && find_header("Clp",nil,path))
|
83
|
+
puts "found"
|
84
|
+
else
|
85
|
+
puts "not found"
|
86
|
+
is_osi = false
|
87
|
+
end
|
88
|
+
|
89
|
+
path = "/usr/lib:/usr/local/lib/"
|
90
|
+
puts "Looking for Cbc (function main) in "+path
|
91
|
+
if(is_osi && find_header("Cbc",nil,path))
|
92
|
+
puts "found"
|
93
|
+
else
|
94
|
+
puts "not found"
|
95
|
+
is_osi = false
|
96
|
+
end
|
97
|
+
|
98
|
+
path = "/usr/lib:/usr/local/lib/"
|
99
|
+
puts "Looking for Cgl (function main) in "+path
|
100
|
+
if(is_osi && find_header("Cgl",nil,path))
|
101
|
+
puts "found"
|
102
|
+
else
|
103
|
+
puts "not found"
|
104
|
+
is_osi = false
|
105
|
+
end
|
106
|
+
|
107
|
+
path = "/usr/lib:/usr/local/lib/"
|
108
|
+
puts "Looking for Osi (function main) in "+path
|
109
|
+
if(is_osi && find_header("Osi",nil,path))
|
110
|
+
puts "found"
|
111
|
+
else
|
112
|
+
puts "not found"
|
113
|
+
is_osi = false
|
114
|
+
end
|
115
|
+
|
116
|
+
path = "/usr/lib:/usr/local/lib/"
|
117
|
+
puts "Looking for OsiClp (function main) in "+path
|
118
|
+
if(is_osi && find_header("Osi",nil,path))
|
119
|
+
puts "found"
|
120
|
+
else
|
121
|
+
puts "not found"
|
122
|
+
is_osi = false
|
123
|
+
end
|
124
|
+
|
125
|
+
path = "/usr/lib:/usr/local/lib/"
|
126
|
+
puts "Looking for CoinUtils (function main) in "+path
|
127
|
+
if(is_cplex && find_header("CoinUtils",nil,path))
|
128
|
+
puts "found"
|
129
|
+
else
|
130
|
+
puts "not found"
|
131
|
+
is_cplex = false
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
else
|
136
|
+
is_cplex = false;
|
137
|
+
is_osi = false;
|
138
|
+
end
|
139
|
+
|
140
|
+
[#r"/opt/ibm/ILOG/CPLEX_Studio126/cplex/bin/x86-64_sles10_4.1/",
|
141
|
+
#os.environ['HOME']+"/source/gurobi510/linux64/lib",
|
142
|
+
|
143
|
+
"Darwin": [os.environ['HOME']+"/Applications/IBM/ILOG/CPLEX_Studio126/cplex/lib/x86-64_osx/static_pic",
|
144
|
+
r"/Library/gurobi560/mac64/lib",
|
145
|
+
r"/Users/mbouchard/source/scipoptsuite-3.0.2/scip-3.0.2/lib/",
|
146
|
+
r"../lib"]
|
147
|
+
}
|
148
|
+
|
149
|
+
|
150
|
+
if(is_cplex)
|
151
|
+
puts "*** With CPLEX_MOUDLE ***"
|
152
|
+
$defs.push("-DCPLEX_MODULE")
|
153
|
+
end
|
154
|
+
if(is_osi)
|
155
|
+
puts "*** With OSI_MOUDLE ***"
|
156
|
+
$defs.push("-DOSI_MODULE")
|
157
|
+
end
|
158
|
+
|
159
|
+
CONFIG["CFLAGS"] = '-O2 -Wall -pthread -fmessage-length=0 -fPIC -std=c++0x'
|
160
|
+
CONFIG["CXX"] = 'g++'
|
161
|
+
|
162
|
+
create_makefile (extension_name)
|
data/lib/Genmodel.rb
ADDED
metadata
CHANGED
@@ -1,47 +1,59 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: genmodel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.21
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Mathieu Bouchard
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-19 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: A generic tool to solve optimization model with different solvers
|
15
14
|
email: mathbouchard@gmail.com
|
16
15
|
executables: []
|
17
|
-
extensions:
|
16
|
+
extensions:
|
17
|
+
- ext/Genmodel/extconf.rb
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
-
-
|
21
|
-
-
|
22
|
-
|
20
|
+
- ext/Genmodel/GenModel.h
|
21
|
+
- ext/Genmodel/GenModelBase.cpp
|
22
|
+
- ext/Genmodel/GenModelCplex.cpp
|
23
|
+
- ext/Genmodel/GenModelCplex.h
|
24
|
+
- ext/Genmodel/GenModelOsi.cpp
|
25
|
+
- ext/Genmodel/GenModelOsi.h
|
26
|
+
- ext/Genmodel/GenModelOsiInterface.cpp
|
27
|
+
- ext/Genmodel/GenModelOsiInterface.h
|
28
|
+
- ext/Genmodel/Genmodel.cpp
|
29
|
+
- ext/Genmodel/InterfaceObject.cpp
|
30
|
+
- ext/Genmodel/InterfaceObject.h
|
31
|
+
- ext/Genmodel/ProblemReaderOsi.cpp
|
32
|
+
- ext/Genmodel/ProblemReaderOsi.h
|
33
|
+
- ext/Genmodel/extconf.rb
|
34
|
+
- lib/Genmodel.rb
|
35
|
+
homepage: https://github.com/mathbouchard/GenModelGem
|
23
36
|
licenses:
|
24
37
|
- MIT
|
38
|
+
metadata: {}
|
25
39
|
post_install_message:
|
26
40
|
rdoc_options: []
|
27
41
|
require_paths:
|
28
42
|
- lib
|
29
43
|
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
-
none: false
|
31
44
|
requirements:
|
32
|
-
- -
|
45
|
+
- - '>='
|
33
46
|
- !ruby/object:Gem::Version
|
34
47
|
version: '0'
|
35
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
-
none: false
|
37
49
|
requirements:
|
38
|
-
- -
|
50
|
+
- - '>='
|
39
51
|
- !ruby/object:Gem::Version
|
40
52
|
version: '0'
|
41
53
|
requirements: []
|
42
54
|
rubyforge_project:
|
43
|
-
rubygems_version:
|
55
|
+
rubygems_version: 2.2.2
|
44
56
|
signing_key:
|
45
|
-
specification_version:
|
57
|
+
specification_version: 4
|
46
58
|
summary: GenModel Gem
|
47
59
|
test_files: []
|
data/lib/genmodel.bundle
DELETED
Binary file
|
data/lib/genmodel.so
DELETED
Binary file
|