genmodel 0.0.48 → 0.0.49
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 +8 -8
- data/ext/Genmodel/GenModel.h +6 -3
- data/ext/Genmodel/GenModelBase.cpp +465 -12
- data/ext/Genmodel/GenModelCplex.cpp +42 -24
- data/ext/Genmodel/GenModelCplex.h +4 -3
- data/ext/Genmodel/Genmodel.cpp +375 -211
- data/ext/Genmodel/extconf.rb +16 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Y2FjZDQ0NDU5YTQ1OGY4MzljMWEyN2ViZDFmMmIxNDNhMWEyNGUxYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjUyYmUxNzkzYjliMmM0ZDM4MzRmNzFiMWI1MDIzYzRlYzIwZWQ2OA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzllMTU1NDQ3YmI0ZTA3YzFkY2YxYjc4MzBkNjYwMzE0Y2NiODI5OTE0YjUw
|
10
|
+
Mjg5N2VjM2FkNDFmMDQxYTFlOWJmNTU3ODUzODZlYjZjOTI5ZjIyZGZiODg4
|
11
|
+
OGRhYjU3ZDliYjllNjk0YmI1ZWEyZTA2YWI5MTRmMDA3MjYzZDg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDRhODcxZGEyZmM0NmVkYzIxNTQ4MTM5MzkxMTI2ZjYzNmMwZDk0YjBhYWY0
|
14
|
+
MjQxMGFiYzEyZDI3YjMzNWViYmUxOGQ1YWU5NjRhYTI3NGEyYWQyMWI3ZGU2
|
15
|
+
Y2EyMzBhY2Q3MTlkYTFjMTI4NDhiNDM1MGNkZWE3NDA5YWIwNjY=
|
data/ext/Genmodel/GenModel.h
CHANGED
@@ -27,6 +27,7 @@
|
|
27
27
|
#include <stdarg.h>
|
28
28
|
#include <float.h>
|
29
29
|
#include <limits>
|
30
|
+
|
30
31
|
|
31
32
|
using namespace std;
|
32
33
|
|
@@ -121,10 +122,11 @@ public:
|
|
121
122
|
virtual long CreateModel() = 0;
|
122
123
|
virtual long Solve() = 0;
|
123
124
|
virtual long SetSol() = 0;
|
124
|
-
virtual long ChangeBulkBounds(
|
125
|
+
virtual long ChangeBulkBounds(size_t count, vector<int>& ind, vector<char>& type, vector<double>& vals);
|
125
126
|
virtual long WriteProblemToLpFile(string filename);
|
126
127
|
virtual long WriteSolutionToFile(string filename);
|
127
|
-
virtual long ChangeBulkObjectives(
|
128
|
+
virtual long ChangeBulkObjectives(size_t count, vector<int>& ind, vector<double>& vals);
|
129
|
+
virtual long ChangeBulkNz(size_t count, vector<int>& rind, vector<int>& cind, vector<double>& vals);
|
128
130
|
virtual long DeleteMipStarts();
|
129
131
|
virtual double GetMIPRelativeGap();
|
130
132
|
virtual double FindConstraintMaxLhs(long row);
|
@@ -135,7 +137,8 @@ public:
|
|
135
137
|
virtual long MakeAllConstraintFeasible(long max_iter = -1);
|
136
138
|
virtual long PrintRowInfo(long row);
|
137
139
|
virtual string GetStatusString();
|
138
|
-
|
140
|
+
string Serialize();
|
141
|
+
long Deserialize(string encoded_compressed_data);
|
139
142
|
bool binit;
|
140
143
|
bool bcreated;
|
141
144
|
string name;
|
@@ -2,6 +2,37 @@
|
|
2
2
|
//#include "SqlCaller.h"
|
3
3
|
#include <math.h>
|
4
4
|
#include <time.h>
|
5
|
+
#include <sstream>
|
6
|
+
#include <zlib.h>
|
7
|
+
#include <sys/time.h>
|
8
|
+
//#include "json.h"
|
9
|
+
#ifdef __MACH__
|
10
|
+
#include <mach/clock.h>
|
11
|
+
#include <mach/mach.h>
|
12
|
+
#endif
|
13
|
+
|
14
|
+
|
15
|
+
void get_perfo_time(timespec& ts)
|
16
|
+
{
|
17
|
+
#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
|
18
|
+
clock_serv_t cclock;
|
19
|
+
mach_timespec_t mts;
|
20
|
+
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
|
21
|
+
clock_get_time(cclock, &mts);
|
22
|
+
mach_port_deallocate(mach_task_self(), cclock);
|
23
|
+
ts.tv_sec = mts.tv_sec;
|
24
|
+
ts.tv_nsec = mts.tv_nsec;
|
25
|
+
#else
|
26
|
+
clock_gettime(CLOCK_REALTIME, &ts);
|
27
|
+
#endif
|
28
|
+
}
|
29
|
+
|
30
|
+
inline double get_timer_diff(timespec& t1, timespec& t2)
|
31
|
+
{
|
32
|
+
return (t2.tv_sec-t1.tv_sec)+(t2.tv_nsec-t1.tv_nsec)/1000000000.0;
|
33
|
+
}
|
34
|
+
|
35
|
+
|
5
36
|
|
6
37
|
#define GM_RED "\x1b[31m"
|
7
38
|
#define GM_GREEN "\x1b[32m"
|
@@ -11,6 +42,230 @@
|
|
11
42
|
#define GM_CYAN "\x1b[36m"
|
12
43
|
#define GM_RESET "\x1b[0m"
|
13
44
|
|
45
|
+
static const string base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
46
|
+
|
47
|
+
static inline bool is_base64(unsigned char c) {
|
48
|
+
return (isalnum(c) || (c == '+') || (c == '/'));
|
49
|
+
}
|
50
|
+
string base64_encode(const unsigned char* bytes_to_encode, unsigned int in_len)
|
51
|
+
{
|
52
|
+
string ret;
|
53
|
+
int i = 0;
|
54
|
+
int j = 0;
|
55
|
+
unsigned char char_array_3[3];
|
56
|
+
unsigned char char_array_4[4];
|
57
|
+
|
58
|
+
while (in_len--)
|
59
|
+
{
|
60
|
+
char_array_3[i++] = *(bytes_to_encode++);
|
61
|
+
if (i == 3)
|
62
|
+
{
|
63
|
+
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
|
64
|
+
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
|
65
|
+
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
|
66
|
+
char_array_4[3] = char_array_3[2] & 0x3f;
|
67
|
+
|
68
|
+
for(i = 0; (i <4) ; i++)
|
69
|
+
ret += base64_chars[char_array_4[i]];
|
70
|
+
i = 0;
|
71
|
+
}
|
72
|
+
}
|
73
|
+
if (i)
|
74
|
+
{
|
75
|
+
for(j = i; j < 3; j++)
|
76
|
+
char_array_3[j] = '\0';
|
77
|
+
|
78
|
+
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
|
79
|
+
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
|
80
|
+
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
|
81
|
+
char_array_4[3] = char_array_3[2] & 0x3f;
|
82
|
+
|
83
|
+
for (j = 0; (j < i + 1); j++)
|
84
|
+
ret += base64_chars[char_array_4[j]];
|
85
|
+
|
86
|
+
while((i++ < 3))
|
87
|
+
ret += '=';
|
88
|
+
}
|
89
|
+
return ret;
|
90
|
+
}
|
91
|
+
|
92
|
+
string base64_decode(const string& encoded_string)
|
93
|
+
{
|
94
|
+
int in_len = encoded_string.size();
|
95
|
+
int i = 0;
|
96
|
+
int j = 0;
|
97
|
+
int in_ = 0;
|
98
|
+
unsigned char char_array_4[4], char_array_3[3];
|
99
|
+
std::string ret;
|
100
|
+
|
101
|
+
while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_]))
|
102
|
+
{
|
103
|
+
char_array_4[i++] = encoded_string[in_]; in_++;
|
104
|
+
if (i ==4)
|
105
|
+
{
|
106
|
+
for (i = 0; i <4; i++)
|
107
|
+
char_array_4[i] = base64_chars.find(char_array_4[i]);
|
108
|
+
|
109
|
+
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
|
110
|
+
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
|
111
|
+
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
|
112
|
+
|
113
|
+
for (i = 0; (i < 3); i++)
|
114
|
+
ret += char_array_3[i];
|
115
|
+
i = 0;
|
116
|
+
}
|
117
|
+
}
|
118
|
+
|
119
|
+
if (i)
|
120
|
+
{
|
121
|
+
for (j = i; j <4; j++)
|
122
|
+
char_array_4[j] = 0;
|
123
|
+
for (j = 0; j <4; j++)
|
124
|
+
char_array_4[j] = base64_chars.find(char_array_4[j]);
|
125
|
+
|
126
|
+
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
|
127
|
+
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
|
128
|
+
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
|
129
|
+
|
130
|
+
for (j = 0; (j < i - 1); j++)
|
131
|
+
ret += char_array_3[j];
|
132
|
+
}
|
133
|
+
return ret;
|
134
|
+
}
|
135
|
+
|
136
|
+
vector<unsigned char> compress_data(unsigned char* data, size_t size, int compressionlevel = Z_DEFAULT_COMPRESSION) //Z_BEST_COMPRESSION)//Z_BEST_SPEED)
|
137
|
+
{
|
138
|
+
z_stream zs; // z_stream is zlib's control structure
|
139
|
+
memset(&zs, 0, sizeof(zs));
|
140
|
+
|
141
|
+
int windowsBits = 15;
|
142
|
+
int GZIP_ENCODING = 16;
|
143
|
+
//if (deflateInit2(&zs, compressionlevel) != Z_OK)
|
144
|
+
|
145
|
+
zs.zalloc = Z_NULL;
|
146
|
+
zs.zfree = Z_NULL;
|
147
|
+
zs.opaque = Z_NULL;
|
148
|
+
if (deflateInit2 (&zs, compressionlevel, Z_DEFLATED, windowsBits | GZIP_ENCODING, 8, Z_DEFAULT_STRATEGY))
|
149
|
+
throw(std::runtime_error("deflateInit failed while compressing."));
|
150
|
+
|
151
|
+
//zs.next_in = (Bytef*)str.data();
|
152
|
+
//zs.avail_in = str.size(); // set the z_stream's input
|
153
|
+
zs.next_in = data;
|
154
|
+
zs.avail_in = size; // set the z_stream's input
|
155
|
+
|
156
|
+
int ret;
|
157
|
+
size_t chunk = 0xffff;
|
158
|
+
size_t avail_size = chunk;
|
159
|
+
if(size/10 > avail_size)
|
160
|
+
avail_size = size/10;
|
161
|
+
size_t buffer_size = avail_size;
|
162
|
+
//vector<unsigned char> outbuffer(32768);
|
163
|
+
//vector<unsigned char> outbuffer(32678);
|
164
|
+
|
165
|
+
//vector<unsigned char> _outbuffer(chunk);
|
166
|
+
|
167
|
+
unsigned char* outbuffer = (unsigned char*) malloc(buffer_size*sizeof(unsigned char));
|
168
|
+
|
169
|
+
size_t current = 0;
|
170
|
+
|
171
|
+
// retrieve the compressed bytes blockwise
|
172
|
+
do {
|
173
|
+
zs.next_out = &(outbuffer[current]);
|
174
|
+
zs.avail_out = avail_size*sizeof(unsigned char);
|
175
|
+
|
176
|
+
ret = deflate(&zs, Z_FINISH);
|
177
|
+
|
178
|
+
if (buffer_size == zs.total_out)
|
179
|
+
{
|
180
|
+
//printf("resize");
|
181
|
+
// append the block to the output string
|
182
|
+
if(buffer_size*0.5 >= chunk)
|
183
|
+
avail_size=buffer_size*0.5;
|
184
|
+
//outbuffer.resize(outbuffer.size()+32768);
|
185
|
+
buffer_size += avail_size;
|
186
|
+
outbuffer = (unsigned char*) realloc(outbuffer, buffer_size*sizeof(unsigned char)); //outbuffer.resize(buffer_size);
|
187
|
+
//else
|
188
|
+
// outbuffer.resize(size_t(outbuffer.size()*1.2));
|
189
|
+
current = zs.total_out;
|
190
|
+
}
|
191
|
+
//else
|
192
|
+
// outbuffer.resize(zs.total_out);
|
193
|
+
} while (ret == Z_OK);
|
194
|
+
|
195
|
+
//outbuffer.resize(zs.total_out);
|
196
|
+
deflateEnd(&zs);
|
197
|
+
|
198
|
+
vector<unsigned char> _outbuffer(zs.total_out);
|
199
|
+
memcpy(&(_outbuffer[0]), outbuffer, zs.total_out);
|
200
|
+
free(outbuffer);
|
201
|
+
|
202
|
+
if (ret != Z_STREAM_END) { // an error occurred that was not EOF
|
203
|
+
std::ostringstream oss;
|
204
|
+
oss << "Exception during zlib compression: (" << ret << ") " << zs.msg;
|
205
|
+
throw(std::runtime_error(oss.str()));
|
206
|
+
}
|
207
|
+
|
208
|
+
return _outbuffer;
|
209
|
+
}
|
210
|
+
|
211
|
+
vector<unsigned char> compress_string(const string& str, int compressionlevel = Z_DEFAULT_COMPRESSION) //Z_BEST_COMPRESSION)//Z_BEST_SPEED)
|
212
|
+
{
|
213
|
+
return compress_data((unsigned char*)str.data(), str.size(), compressionlevel);
|
214
|
+
}
|
215
|
+
|
216
|
+
|
217
|
+
char* decompress_string(const string& compressedBytes) {
|
218
|
+
|
219
|
+
if ( compressedBytes.size() == 0 )
|
220
|
+
return NULL;
|
221
|
+
|
222
|
+
size_t full_length = compressedBytes.size();
|
223
|
+
size_t half_length = compressedBytes.size()/2;
|
224
|
+
|
225
|
+
size_t uncompLength = full_length ;
|
226
|
+
char* uncomp = (char*) calloc( sizeof(char), uncompLength );
|
227
|
+
|
228
|
+
z_stream strm;
|
229
|
+
strm.next_in = (Bytef *) compressedBytes.c_str();
|
230
|
+
strm.avail_in = compressedBytes.size() ;
|
231
|
+
strm.total_out = 0;
|
232
|
+
strm.zalloc = Z_NULL;
|
233
|
+
strm.zfree = Z_NULL;
|
234
|
+
|
235
|
+
bool done = false ;
|
236
|
+
|
237
|
+
if (inflateInit2(&strm, (16+MAX_WBITS)) != Z_OK)
|
238
|
+
{
|
239
|
+
free( uncomp );
|
240
|
+
return NULL;
|
241
|
+
}
|
242
|
+
|
243
|
+
while (!done)
|
244
|
+
{
|
245
|
+
// If our output buffer is too small
|
246
|
+
if (strm.total_out >= uncompLength )
|
247
|
+
uncomp = (char*) realloc(uncomp, uncompLength += half_length);
|
248
|
+
|
249
|
+
strm.next_out = (Bytef *) (uncomp + strm.total_out);
|
250
|
+
strm.avail_out = uncompLength - strm.total_out;
|
251
|
+
|
252
|
+
int err = inflate (&strm, Z_SYNC_FLUSH);
|
253
|
+
if (err == Z_STREAM_END)
|
254
|
+
done = true;
|
255
|
+
else if (err != Z_OK)
|
256
|
+
break;
|
257
|
+
}
|
258
|
+
|
259
|
+
if (inflateEnd (&strm) != Z_OK)
|
260
|
+
{
|
261
|
+
free( uncomp );
|
262
|
+
return NULL;
|
263
|
+
}
|
264
|
+
uncomp = (char*) realloc(uncomp, strm.total_out);
|
265
|
+
|
266
|
+
return uncomp;
|
267
|
+
}
|
268
|
+
|
14
269
|
GenModel::GenModel()
|
15
270
|
{
|
16
271
|
version = "genmodel-0.0.39 build 0001";
|
@@ -358,16 +613,24 @@ long GenModel::AddModelRow(vector<int>& ind, vector<double>& val, double rhs, ch
|
|
358
613
|
return 0;
|
359
614
|
}
|
360
615
|
|
361
|
-
long GenModel::ChangeBulkBounds(
|
616
|
+
long GenModel::ChangeBulkBounds(size_t count, vector<int>& ind, vector<char>& type, vector<double>& vals)
|
362
617
|
{
|
618
|
+
throw string("WriteProblemToLpFile() Not implemented");
|
363
619
|
return 0;
|
364
620
|
}
|
365
621
|
|
366
|
-
long GenModel::ChangeBulkObjectives(
|
622
|
+
long GenModel::ChangeBulkObjectives(size_t count, vector<int>& ind, vector<double>& vals)
|
367
623
|
{
|
624
|
+
throw string("WriteProblemToLpFile() Not implemented");
|
368
625
|
return 0;
|
369
626
|
}
|
370
627
|
|
628
|
+
long GenModel::ChangeBulkNz(size_t count, vector<int>& rind, vector<int>& cind, vector<double>& vals)
|
629
|
+
{
|
630
|
+
throw string("WriteProblemToLpFile() Not implemented");
|
631
|
+
return 0;
|
632
|
+
}
|
633
|
+
|
371
634
|
long GenModel::WriteProblemToLpFile(string filename)
|
372
635
|
{
|
373
636
|
throw string("WriteProblemToLpFile() Not implemented");
|
@@ -399,17 +662,207 @@ string GenModel::GetStatusString()
|
|
399
662
|
return string(cstr);
|
400
663
|
}
|
401
664
|
|
402
|
-
|
665
|
+
string GenModel::Serialize()
|
666
|
+
{
|
667
|
+
SetNumbers();
|
668
|
+
|
669
|
+
// Serial
|
670
|
+
// nb_vars
|
671
|
+
// vars_obj
|
672
|
+
// vars type
|
673
|
+
// var_ub
|
674
|
+
// var_lb
|
675
|
+
// var_q_size
|
676
|
+
// var_qobj
|
677
|
+
// var_qi
|
678
|
+
// var_qj
|
679
|
+
// nb_consts
|
680
|
+
// consts_lrhs
|
681
|
+
// consts_sense
|
682
|
+
// consts_urhs
|
683
|
+
// consts_nz
|
684
|
+
// matrix_per_row_index
|
685
|
+
// matrix_per_row_value
|
686
|
+
|
687
|
+
|
688
|
+
timespec t1; get_perfo_time(t1);
|
689
|
+
|
690
|
+
|
691
|
+
unsigned long nb_qz = vars.qobj.size();
|
692
|
+
size_t var_size = 2*sizeof(unsigned long) + nc*(/*type*/sizeof(char) + /*obj,ub,lb*/ 3*sizeof(double)) + nb_qz*(/*qobj*/ sizeof(double) + /*qi,qj*/ 2*sizeof(long));
|
693
|
+
size_t const_size = sizeof(unsigned long) + nr*(/*type*/sizeof(char) + /*lrhs,urhs*/ 2*sizeof(double));
|
694
|
+
size_t mat_size = nr*sizeof(unsigned long);
|
695
|
+
|
696
|
+
for(size_t i = 0; i < nr; ++i)
|
697
|
+
mat_size += consts[i].nz*(sizeof(long)+sizeof(double));
|
698
|
+
size_t total_size = var_size+const_size+mat_size;
|
699
|
+
|
700
|
+
unsigned char* data = (unsigned char*) malloc(total_size+1);
|
701
|
+
size_t offset = 0;
|
702
|
+
memcpy(&(data[offset]), &(nc), sizeof(unsigned long));
|
703
|
+
offset += sizeof(unsigned long);
|
704
|
+
memcpy(&(data[offset]), &(vars.obj[0]), nc*sizeof(double));
|
705
|
+
offset += nc*sizeof(double);
|
706
|
+
memcpy(&(data[offset]), &(vars.type[0]), nc*sizeof(char));
|
707
|
+
offset += nc*sizeof(char);
|
708
|
+
memcpy(&(data[offset]), &(vars.ub[0]), nc*sizeof(double));
|
709
|
+
offset += nc*sizeof(double);
|
710
|
+
memcpy(&(data[offset]), &(vars.lb[0]), nc*sizeof(double));
|
711
|
+
offset += nc*sizeof(double);
|
712
|
+
//printf("> offset before nq = %lu\n", offset);
|
713
|
+
memcpy(&(data[offset]), &(nb_qz), sizeof(unsigned long));
|
714
|
+
offset += sizeof(unsigned long);
|
715
|
+
memcpy(&(data[offset]), &(vars.qobj[0]), nb_qz*sizeof(double));
|
716
|
+
offset += nb_qz*sizeof(double);
|
717
|
+
memcpy(&(data[offset]), &(vars.qi[0]), nb_qz*sizeof(long));
|
718
|
+
offset += nb_qz*sizeof(long);
|
719
|
+
memcpy(&(data[offset]), &(vars.qj[0]), nb_qz*sizeof(long));
|
720
|
+
offset += nb_qz*sizeof(long);
|
721
|
+
|
722
|
+
//printf("> offset before nr = %lu\n", offset);
|
723
|
+
memcpy(&(data[offset]), &(nr), sizeof(unsigned long));
|
724
|
+
offset += sizeof(unsigned long);
|
725
|
+
for(size_t i = 0; i < nr; ++i)
|
726
|
+
{
|
727
|
+
//if (i>0 && i%1000 == 0)
|
728
|
+
// printf("constraint info %lu / %lu\n", i, nr);
|
729
|
+
memcpy(&(data[offset]), &(consts[i].lrhs), sizeof(double));
|
730
|
+
offset += sizeof(double);
|
731
|
+
memcpy(&(data[offset]), &(consts[i].sense), sizeof(char));
|
732
|
+
offset += sizeof(char);
|
733
|
+
memcpy(&(data[offset]), &(consts[i].urhs), sizeof(double));
|
734
|
+
offset += sizeof(double);
|
735
|
+
}
|
736
|
+
for(size_t i = 0; i < nr; ++i)
|
737
|
+
{
|
738
|
+
//if (i>0 && i%1000 == 0)
|
739
|
+
// printf("matrix element %lu / %lu\n", i, nr);
|
740
|
+
memcpy(&(data[offset]), &(consts[i].nz), sizeof(unsigned long));
|
741
|
+
offset += sizeof(unsigned long);
|
742
|
+
memcpy(&(data[offset]), &(consts[i].cols[0]), consts[i].nz*sizeof(long));
|
743
|
+
offset += consts[i].nz*sizeof(long);
|
744
|
+
memcpy(&(data[offset]), &(consts[i].coefs[0]), consts[i].nz*sizeof(double));
|
745
|
+
offset += consts[i].nz*sizeof(double);
|
746
|
+
}
|
747
|
+
//printf("> offset at end = %lu\n", offset);
|
748
|
+
data[offset] = '\0';
|
749
|
+
printf("var_size = %lu, const_size = %lu mat_size = %lu, total_size = %lu\n", var_size, const_size, mat_size, total_size);
|
750
|
+
//printf("> nc = %lu, nr = %lu, nq = %lu, nz = %lu\n", nc, nr, vars.qobj.size(), nz);
|
751
|
+
|
752
|
+
timespec t2; get_perfo_time(t2);
|
753
|
+
printf("Serialize : write serilization to memory : %f s.\n", get_timer_diff(t1,t2));
|
754
|
+
|
755
|
+
vector<unsigned char> compressed_data = compress_data(data, total_size);
|
756
|
+
timespec t3; get_perfo_time(t3);
|
757
|
+
printf("Serialize : compressing serilization : %f s.\n", get_timer_diff(t2,t3));
|
758
|
+
free(data);
|
759
|
+
string serialization_str = base64_encode(&(compressed_data[0]), compressed_data.size());
|
760
|
+
timespec t4; get_perfo_time(t4);
|
761
|
+
printf("Serialize : encoding serilization : %f s.\n", get_timer_diff(t3,t4));
|
762
|
+
|
763
|
+
return serialization_str;
|
764
|
+
}
|
765
|
+
|
766
|
+
long GenModel::Deserialize(string encoded_compressed_data)
|
403
767
|
{
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
768
|
+
timespec t1; get_perfo_time(t1);
|
769
|
+
|
770
|
+
nr = 0;
|
771
|
+
nc = 0;
|
772
|
+
nz = 0;
|
773
|
+
|
774
|
+
for(size_t i = 0; i < consts.size(); ++i)
|
775
|
+
{
|
776
|
+
consts[i].cols.clear();
|
777
|
+
consts[i].coefs.clear();
|
778
|
+
}
|
779
|
+
consts.clear();
|
780
|
+
|
781
|
+
vars = ModVars();
|
782
|
+
timespec t2; get_perfo_time(t2);
|
783
|
+
printf("Deserialize : freeing object : %f s.", get_timer_diff(t1,t2));
|
784
|
+
|
785
|
+
string decoded_string = base64_decode(encoded_compressed_data);
|
786
|
+
timespec t3; get_perfo_time(t3);
|
787
|
+
printf("Deserialize : decoding serialization : %f s.", get_timer_diff(t2,t3));
|
788
|
+
|
789
|
+
char* data = decompress_string(decoded_string);
|
790
|
+
timespec t4; get_perfo_time(t4);
|
791
|
+
printf("Deserialize : decompressing serialization : %f s.", get_timer_diff(t3,t4));
|
792
|
+
|
793
|
+
|
794
|
+
size_t offset = 0;
|
795
|
+
memcpy(&nc, &(data[offset]), sizeof(unsigned long));
|
796
|
+
vars.n = nc;
|
797
|
+
offset += sizeof(unsigned long);
|
798
|
+
vars.name.resize(nc, "");
|
799
|
+
vars.obj.resize(nc);
|
800
|
+
memcpy(&(vars.obj[0]), &(data[offset]), nc*sizeof(double));
|
801
|
+
offset += nc*sizeof(double);
|
802
|
+
vars.type.resize(nc);
|
803
|
+
memcpy(&(vars.type[0]), &(data[offset]), nc*sizeof(char));
|
804
|
+
offset += nc*sizeof(char);
|
805
|
+
vars.ub.resize(nc);
|
806
|
+
memcpy(&(vars.ub[0]), &(data[offset]), nc*sizeof(double));
|
807
|
+
offset += nc*sizeof(double);
|
808
|
+
vars.lb.resize(nc);
|
809
|
+
memcpy(&(vars.lb[0]), &(data[offset]), nc*sizeof(double));
|
810
|
+
offset += nc*sizeof(double);
|
811
|
+
//printf("< offset before nq = %lu\n", offset);
|
812
|
+
unsigned long nb_qz = 0;
|
813
|
+
memcpy(&nb_qz, &(data[offset]), sizeof(unsigned long));
|
814
|
+
offset += sizeof(unsigned long);
|
815
|
+
vars.qobj.resize(nb_qz);
|
816
|
+
memcpy(&(vars.qobj[0]), &(data[offset]), nb_qz*sizeof(double));
|
817
|
+
offset += nb_qz*sizeof(double);
|
818
|
+
vars.qi.resize(nb_qz);
|
819
|
+
memcpy(&(vars.qi[0]), &(data[offset]), nb_qz*sizeof(long));
|
820
|
+
offset += nb_qz*sizeof(long);
|
821
|
+
vars.qj.resize(nb_qz);
|
822
|
+
memcpy(&(vars.qj[0]), &(data[offset]), nb_qz*sizeof(long));
|
823
|
+
offset += nb_qz*sizeof(long);
|
824
|
+
|
825
|
+
//printf("< offset before nr = %lu\n", offset);
|
826
|
+
memcpy(&nr, &(data[offset]), sizeof(unsigned long));
|
827
|
+
offset += sizeof(unsigned long);
|
828
|
+
|
829
|
+
consts.resize(nr);
|
830
|
+
for(size_t i = 0; i < nr; ++i)
|
831
|
+
{
|
832
|
+
memcpy(&(consts[i].lrhs), &(data[offset]), sizeof(double));
|
833
|
+
offset += sizeof(double);
|
834
|
+
memcpy(&(consts[i].sense), &(data[offset]), sizeof(char));
|
835
|
+
offset += sizeof(char);
|
836
|
+
memcpy(&(consts[i].urhs), &(data[offset]), sizeof(double));
|
837
|
+
offset += sizeof(double);
|
838
|
+
consts[i].name = "";
|
839
|
+
}
|
840
|
+
|
841
|
+
unsigned long r_nz;
|
842
|
+
for(size_t i = 0; i < nr; ++i)
|
843
|
+
{
|
844
|
+
memcpy(&r_nz, &(data[offset]), sizeof(long));
|
845
|
+
offset += sizeof(long);
|
846
|
+
consts[i].cols.resize(r_nz);
|
847
|
+
memcpy(&(consts[i].cols[0]), &(data[offset]), r_nz*sizeof(long));
|
848
|
+
offset += r_nz*sizeof(long);
|
849
|
+
consts[i].coefs.resize(r_nz);
|
850
|
+
memcpy(&(consts[i].coefs[0]), &(data[offset]), r_nz*sizeof(double));
|
851
|
+
offset += r_nz*sizeof(double);
|
852
|
+
}
|
853
|
+
//printf("< offset at end = %lu\n", offset);
|
854
|
+
|
855
|
+
SetNumbers();
|
856
|
+
|
857
|
+
free(data);
|
858
|
+
|
859
|
+
//printf("< nc = %lu, nr = %lu, nq = %lu, nz = %lu\n", nc, nr, nb_qz, nz);
|
860
|
+
|
861
|
+
timespec t5; get_perfo_time(t5);
|
862
|
+
printf("Deserialize : filling object : %f s.", get_timer_diff(t4,t5));
|
863
|
+
|
864
|
+
return 0;
|
865
|
+
}
|
413
866
|
|
414
867
|
long ModVars::AddVar(string nn, double o, double l, double u, char t)
|
415
868
|
{
|