summaryrefslogtreecommitdiff
path: root/python-rmol.spec
blob: 18e8d6ec56d9c8c28023f1f9fe7a16514a894894 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
%global _empty_manifest_terminate_build 0
Name:		python-rmol
Version:	1.0.6.post1
Release:	1
Summary:	Simple Python wrapper for RMOL
License:	MIT
URL:		https://github.com/airsim/rmol
Source0:	https://mirrors.nju.edu.cn/pypi/web/packages/16/d3/f1c69e6f91e2a6cd6fd87bfa9b75b633674b7f2ecf681e17bc59f960591d/rmol-1.0.6.post1.tar.gz
BuildArch:	noarch


%description
# Summary
RMOL is a C++ library of Revenue Management and Optimisation classes 
and functions. Typically, that library may be used by service providers
(_e.g._, airlines offering flight seats, hotels offering rooms, rental car
companies offering rental days, broadcasting company offering advertisement 
slots, theaters offering seats, _etc_) to help in optimising their revenues 
from seat capacities.
Most of the algorithms implemented are public and documented in the 
following book:
The Theory and practice of Revenue Management, by Kalyan T. Talluri and
Garrett J. van Ryzin, Kluwer Academic Publishers, 2004, ISBN 1-4020-7701-7
RMOL makes an extensive use of existing open-source libraries for
increased functionality, speed and accuracy. In particular the
Boost (C++ Standard Extensions: http://www.boost.org) library is used.
RMOL is the one of the components of the Travel Market Simulator
(https://travel-sim.org). However, it may be used in a
stand-alone mode.
# Installation
## On Fedora/CentOS/RedHat distribution
Just use DNF:
```bash
$ dnf -y install rmol-devel rmol-doc
```
You can also get the RPM packages (which may work on Linux
distributions like Suse and Mandriva) from the Fedora repository
(_e.g._, for Fedora 32, 
https://fr2.rpmfind.net/linux/RPM/fedora/32/x86_64/)
## Building the library and test binary from Git repository
The Git repository may be cloned as following:
```bash
$ git clone git@github.com:airsim/rmol.git rmolgit # through SSH
$ git clone https://github.com/airsim/rmol.git # if the firewall filters SSH
$ cd rmolgit
```
Then, you need the following packages (Fedora/RedHat/CentOS names here, 
but names may vary according to distributions):
* `cmake`
* `gcc-c++`
* `boost-devel` / `libboost-dev`
* `python-devel` / `python-dev`
* `gettext-devel` / `gettext`
* `sqlite3-devel` / `libsqlite3-dev`
* `readline-devel` / `libreadline-dev`
* `libncurses5-devel`
* `soci-mysql-devel`, `soci-sqlite3-devel`
* `stdair-devel` / `libstdair-dev`
* `airrac-devel` / `libairrac-dev`
* `doxygen`, `ghostscript`, `graphviz`
* `tetex-latex` (optional)
* `rpm-build` (optional)
## Building the library and test binary from the tarball
The latest stable source tarball (`rmol*.tar.gz` or `.bz2`) can be
found on GitHub: http://github.com/airsim/rmol/releases, _e.g._,
https://github.com/airsim/rmol/archive/rmol-1.00.6.tar.gz
As RMOL depends on other
[Travel Market Simulator (TvlSim/AirSim)](https://github.com/airsim/)
modules, more specifically [StdAir](https://github.com/airsim/stdair)
and [AirRAC](https://github.com/airsim/airrac), it may be
convenient to use the
[MetaSim project](https://github.com/airsim/metasim),
which pulls at once all the components of TvlSim in the same place,
and then orchestrates the dependencies for the builds, installations
and use of components.
If MetaSim is not used, in order to customise the following to your
environment, you can alter the path to the installation directory:
```bash
export INSTALL_BASEDIR="${HOME}/dev/deliveries"
export RMOL_VER="1.00.6"
if [ -d /usr/lib64 ]; then LIBSUFFIX="64"; fi
export LIBSUFFIX_4_CMAKE="-DLIB_SUFFIX=$LIBSUFFIX"
```
Then, as usual:
* To configure the project, type something like:
```bash
  mkdir build && cd build
  cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_BASEDIR}/rmol-$RMOL_VER \
   -DWITH_STDAIR_PREFIX=${INSTALL_BASEDIR}/stdair-stable \
   -DWITH_AIRRAC_PREFIX=${INSTALL_BASEDIR}/airrac-stable \
   -DCMAKE_BUILD_TYPE:STRING=Debug -DENABLE_TEST:BOOL=ON -DINSTALL_DOC:BOOL=ON \
   -DRUN_GCOV:BOOL=OFF ${LIBSUFFIX_4_CMAKE} ..
   ${LIBSUFFIX_4_CMAKE} ..
```
* To build the project, type:
```bash
  make
```
* To test the project, type:
```bash
  make check
```
* To install the library (`librmol*.so*`) and the binary (`rmol`),
```bash
  make install
  cd ${INSTALL_BASEDIR}
  rm -f rmol-stable && ln -s rmol-${RMOL_VER} rmol-stable
  cd -
```
* To package the source files, type:
```bash
  make dist
```
* To package the binary and the (HTML and PDF) documentation:
```bash
  make package
```
* To browse the (just installed, if enabled) HTML documentation:
```bash
  open file://${INSTALL_BASEDIR}/rmol-${RMOL_VER}/share/doc/rmol/html/index.html
```
* To browse the (just installed, if enabled) PDF documentation:
```bash
  open ${INSTALL_BASEDIR}/rmol-${RMOL_VER}/share/doc/rmol/html/refman.pdf
```
* To run the local binary version:
```
  ./rmol/rmol -b
```
* To run the installed version:
```bash
  ${INSTALL_BASEDIR}/rmol-$RMOL_VER/bin/rmol -b
```
# Python extension
The way to interact with a C++-based Python extension is extensively described
in the [OpenTREP project](https://github.com/trep/opentrep).
Only a quick start is given here.
## Python dependencies
* Install Python dependencies:
```bash
$ python3 -m pip install -U pip
$ python3 -m pip install -U wheel
$ python3 -m pip install -U build setuptools scikit-build tox pytest sphinx twine
```
## Build the Python extension
* Build the Python extension with SciKit-Build:
```bash
$ rm -rf _skbuild/ dist/ MANIFEST_
$ python3 setup.py --build-type=Debug build sdist bdist_wheel
```
* The Python artifacts should be similar to:
```bash
$ ls -lFh dist/
total 5872
-rw-r--r-- 1 user staff 2.0M Jun  1 15:49 rmol-1.0.5.post1-cp38-cp38-macosx_10_15_x86_64.whl
-rw-r--r-- 1 user staff 834K Jun  1 15:49 rmol-1.0.5.post1.tar.gz
```
* Updload the RMOL Python extension onto PyPi:
```bash
$ twine upload -u __token__ --repository-url https://upload.pypi.org/legacy/ dist/*
```
* The RMOL Python artifacts may then be browsed on PyyPI:
  https://pypi.org/project/rmol/
## Use the Python extension
* Launch the Python interpreter:
```bash
$ export PYTHONPATH=${PWD}/_skbuild/macosx-10.15-x86_64-3.8/cmake-install/lib:${PWD}/_skbuild/macosx-10.15-x86_64-3.8/cmake-install/lib/python3.8/site-packages/pyrmol
$ DYLD_INSERT_LIBRARIES=/Library/Developer/CommandLineTools/usr/lib/clang/11.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib ASAN_OPTIONS=detect_container_overflow=0 /usr/local/Cellar/python@3.8/3.8.3/Frameworks/Python.framework/Versions/3.8/Resources/Python.app/Contents/MacOS/Python
```
* Within the Python interpreter, import, initialize
  and use the RMOL Python extension:
```python
Python 3.8.3 (default, May 27 2020, 20:54:22) 
[Clang 11.0.3 (clang-1103.0.32.59)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyrmol
>>> rmolLibrary = pyrmol.RMOLer()
>>> rmolLibrary.init('rmol.log', 40, 1, '')
True
>>> rmolLibrary.rmol(100, 10, 40.0)
'RMOL has completed the generation of the booking requests. See the log file for more details.\n'
>>> quit()
```
* Back to the Shell session, look for the results in the RMOL log file:
```bash
$ cat rmol.log
Python wrapper initialisation
[D]${STDAIR_PREFIX}/stdair/command/CmdBomManager.cpp:52: StdAir is building the BOM tree from built-in specifications.
Python wrapper initialised
Optimisation for 100 draws, capacity of 40, and with the following method: 10
[D]${RMOL_PREFIX}/rmol/service/RMOL_Service.cpp:491: Optimisation by Monte-Carlo performed in 0.000321
[D]${RMOL_PREFIX}/rmol/service/RMOL_Service.cpp:492: Result: 
Yield: 100.00, Protection: 70.48, Booking limit: 100.00
Yield: 70.00, Protection: 156.19, Booking limit: 29.52
Yield: 42.00, Protection: -0.00, Booking limit: -56.19
[D]${RMOL_PREFIX}/rmol/service/RMOL_Service.cpp:505: Bid-Price Vector (BPV): 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 99.00, 99.00, 99.00, 99.00, 99.00, 98.00, 98.00, 97.00, 96.00, 96.00, 96.00, 96.00, 96.00, 95.00, 94.00, 94.00, 90.00, 90.00, 89.00, 88.00, 86.00, 84.00, 82.00, 80.00, 80.00, 79.00, 77.00, 76.00, 75.00, 72.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00
End of the optimisation.
RMOL output: 
```
* Of course, a few more features could be added to the Python extension API,
  in order not to have to leave the Python interpreter to interact with the
  results of invoking the optimizer. Do not hesitate to contribute
  through [Pull Requests](https://github.com/airsim/rmol/pulls), which are
  always welcome!

%package -n python3-rmol
Summary:	Simple Python wrapper for RMOL
Provides:	python-rmol
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-rmol
# Summary
RMOL is a C++ library of Revenue Management and Optimisation classes 
and functions. Typically, that library may be used by service providers
(_e.g._, airlines offering flight seats, hotels offering rooms, rental car
companies offering rental days, broadcasting company offering advertisement 
slots, theaters offering seats, _etc_) to help in optimising their revenues 
from seat capacities.
Most of the algorithms implemented are public and documented in the 
following book:
The Theory and practice of Revenue Management, by Kalyan T. Talluri and
Garrett J. van Ryzin, Kluwer Academic Publishers, 2004, ISBN 1-4020-7701-7
RMOL makes an extensive use of existing open-source libraries for
increased functionality, speed and accuracy. In particular the
Boost (C++ Standard Extensions: http://www.boost.org) library is used.
RMOL is the one of the components of the Travel Market Simulator
(https://travel-sim.org). However, it may be used in a
stand-alone mode.
# Installation
## On Fedora/CentOS/RedHat distribution
Just use DNF:
```bash
$ dnf -y install rmol-devel rmol-doc
```
You can also get the RPM packages (which may work on Linux
distributions like Suse and Mandriva) from the Fedora repository
(_e.g._, for Fedora 32, 
https://fr2.rpmfind.net/linux/RPM/fedora/32/x86_64/)
## Building the library and test binary from Git repository
The Git repository may be cloned as following:
```bash
$ git clone git@github.com:airsim/rmol.git rmolgit # through SSH
$ git clone https://github.com/airsim/rmol.git # if the firewall filters SSH
$ cd rmolgit
```
Then, you need the following packages (Fedora/RedHat/CentOS names here, 
but names may vary according to distributions):
* `cmake`
* `gcc-c++`
* `boost-devel` / `libboost-dev`
* `python-devel` / `python-dev`
* `gettext-devel` / `gettext`
* `sqlite3-devel` / `libsqlite3-dev`
* `readline-devel` / `libreadline-dev`
* `libncurses5-devel`
* `soci-mysql-devel`, `soci-sqlite3-devel`
* `stdair-devel` / `libstdair-dev`
* `airrac-devel` / `libairrac-dev`
* `doxygen`, `ghostscript`, `graphviz`
* `tetex-latex` (optional)
* `rpm-build` (optional)
## Building the library and test binary from the tarball
The latest stable source tarball (`rmol*.tar.gz` or `.bz2`) can be
found on GitHub: http://github.com/airsim/rmol/releases, _e.g._,
https://github.com/airsim/rmol/archive/rmol-1.00.6.tar.gz
As RMOL depends on other
[Travel Market Simulator (TvlSim/AirSim)](https://github.com/airsim/)
modules, more specifically [StdAir](https://github.com/airsim/stdair)
and [AirRAC](https://github.com/airsim/airrac), it may be
convenient to use the
[MetaSim project](https://github.com/airsim/metasim),
which pulls at once all the components of TvlSim in the same place,
and then orchestrates the dependencies for the builds, installations
and use of components.
If MetaSim is not used, in order to customise the following to your
environment, you can alter the path to the installation directory:
```bash
export INSTALL_BASEDIR="${HOME}/dev/deliveries"
export RMOL_VER="1.00.6"
if [ -d /usr/lib64 ]; then LIBSUFFIX="64"; fi
export LIBSUFFIX_4_CMAKE="-DLIB_SUFFIX=$LIBSUFFIX"
```
Then, as usual:
* To configure the project, type something like:
```bash
  mkdir build && cd build
  cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_BASEDIR}/rmol-$RMOL_VER \
   -DWITH_STDAIR_PREFIX=${INSTALL_BASEDIR}/stdair-stable \
   -DWITH_AIRRAC_PREFIX=${INSTALL_BASEDIR}/airrac-stable \
   -DCMAKE_BUILD_TYPE:STRING=Debug -DENABLE_TEST:BOOL=ON -DINSTALL_DOC:BOOL=ON \
   -DRUN_GCOV:BOOL=OFF ${LIBSUFFIX_4_CMAKE} ..
   ${LIBSUFFIX_4_CMAKE} ..
```
* To build the project, type:
```bash
  make
```
* To test the project, type:
```bash
  make check
```
* To install the library (`librmol*.so*`) and the binary (`rmol`),
```bash
  make install
  cd ${INSTALL_BASEDIR}
  rm -f rmol-stable && ln -s rmol-${RMOL_VER} rmol-stable
  cd -
```
* To package the source files, type:
```bash
  make dist
```
* To package the binary and the (HTML and PDF) documentation:
```bash
  make package
```
* To browse the (just installed, if enabled) HTML documentation:
```bash
  open file://${INSTALL_BASEDIR}/rmol-${RMOL_VER}/share/doc/rmol/html/index.html
```
* To browse the (just installed, if enabled) PDF documentation:
```bash
  open ${INSTALL_BASEDIR}/rmol-${RMOL_VER}/share/doc/rmol/html/refman.pdf
```
* To run the local binary version:
```
  ./rmol/rmol -b
```
* To run the installed version:
```bash
  ${INSTALL_BASEDIR}/rmol-$RMOL_VER/bin/rmol -b
```
# Python extension
The way to interact with a C++-based Python extension is extensively described
in the [OpenTREP project](https://github.com/trep/opentrep).
Only a quick start is given here.
## Python dependencies
* Install Python dependencies:
```bash
$ python3 -m pip install -U pip
$ python3 -m pip install -U wheel
$ python3 -m pip install -U build setuptools scikit-build tox pytest sphinx twine
```
## Build the Python extension
* Build the Python extension with SciKit-Build:
```bash
$ rm -rf _skbuild/ dist/ MANIFEST_
$ python3 setup.py --build-type=Debug build sdist bdist_wheel
```
* The Python artifacts should be similar to:
```bash
$ ls -lFh dist/
total 5872
-rw-r--r-- 1 user staff 2.0M Jun  1 15:49 rmol-1.0.5.post1-cp38-cp38-macosx_10_15_x86_64.whl
-rw-r--r-- 1 user staff 834K Jun  1 15:49 rmol-1.0.5.post1.tar.gz
```
* Updload the RMOL Python extension onto PyPi:
```bash
$ twine upload -u __token__ --repository-url https://upload.pypi.org/legacy/ dist/*
```
* The RMOL Python artifacts may then be browsed on PyyPI:
  https://pypi.org/project/rmol/
## Use the Python extension
* Launch the Python interpreter:
```bash
$ export PYTHONPATH=${PWD}/_skbuild/macosx-10.15-x86_64-3.8/cmake-install/lib:${PWD}/_skbuild/macosx-10.15-x86_64-3.8/cmake-install/lib/python3.8/site-packages/pyrmol
$ DYLD_INSERT_LIBRARIES=/Library/Developer/CommandLineTools/usr/lib/clang/11.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib ASAN_OPTIONS=detect_container_overflow=0 /usr/local/Cellar/python@3.8/3.8.3/Frameworks/Python.framework/Versions/3.8/Resources/Python.app/Contents/MacOS/Python
```
* Within the Python interpreter, import, initialize
  and use the RMOL Python extension:
```python
Python 3.8.3 (default, May 27 2020, 20:54:22) 
[Clang 11.0.3 (clang-1103.0.32.59)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyrmol
>>> rmolLibrary = pyrmol.RMOLer()
>>> rmolLibrary.init('rmol.log', 40, 1, '')
True
>>> rmolLibrary.rmol(100, 10, 40.0)
'RMOL has completed the generation of the booking requests. See the log file for more details.\n'
>>> quit()
```
* Back to the Shell session, look for the results in the RMOL log file:
```bash
$ cat rmol.log
Python wrapper initialisation
[D]${STDAIR_PREFIX}/stdair/command/CmdBomManager.cpp:52: StdAir is building the BOM tree from built-in specifications.
Python wrapper initialised
Optimisation for 100 draws, capacity of 40, and with the following method: 10
[D]${RMOL_PREFIX}/rmol/service/RMOL_Service.cpp:491: Optimisation by Monte-Carlo performed in 0.000321
[D]${RMOL_PREFIX}/rmol/service/RMOL_Service.cpp:492: Result: 
Yield: 100.00, Protection: 70.48, Booking limit: 100.00
Yield: 70.00, Protection: 156.19, Booking limit: 29.52
Yield: 42.00, Protection: -0.00, Booking limit: -56.19
[D]${RMOL_PREFIX}/rmol/service/RMOL_Service.cpp:505: Bid-Price Vector (BPV): 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 99.00, 99.00, 99.00, 99.00, 99.00, 98.00, 98.00, 97.00, 96.00, 96.00, 96.00, 96.00, 96.00, 95.00, 94.00, 94.00, 90.00, 90.00, 89.00, 88.00, 86.00, 84.00, 82.00, 80.00, 80.00, 79.00, 77.00, 76.00, 75.00, 72.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00
End of the optimisation.
RMOL output: 
```
* Of course, a few more features could be added to the Python extension API,
  in order not to have to leave the Python interpreter to interact with the
  results of invoking the optimizer. Do not hesitate to contribute
  through [Pull Requests](https://github.com/airsim/rmol/pulls), which are
  always welcome!

%package help
Summary:	Development documents and examples for rmol
Provides:	python3-rmol-doc
%description help
# Summary
RMOL is a C++ library of Revenue Management and Optimisation classes 
and functions. Typically, that library may be used by service providers
(_e.g._, airlines offering flight seats, hotels offering rooms, rental car
companies offering rental days, broadcasting company offering advertisement 
slots, theaters offering seats, _etc_) to help in optimising their revenues 
from seat capacities.
Most of the algorithms implemented are public and documented in the 
following book:
The Theory and practice of Revenue Management, by Kalyan T. Talluri and
Garrett J. van Ryzin, Kluwer Academic Publishers, 2004, ISBN 1-4020-7701-7
RMOL makes an extensive use of existing open-source libraries for
increased functionality, speed and accuracy. In particular the
Boost (C++ Standard Extensions: http://www.boost.org) library is used.
RMOL is the one of the components of the Travel Market Simulator
(https://travel-sim.org). However, it may be used in a
stand-alone mode.
# Installation
## On Fedora/CentOS/RedHat distribution
Just use DNF:
```bash
$ dnf -y install rmol-devel rmol-doc
```
You can also get the RPM packages (which may work on Linux
distributions like Suse and Mandriva) from the Fedora repository
(_e.g._, for Fedora 32, 
https://fr2.rpmfind.net/linux/RPM/fedora/32/x86_64/)
## Building the library and test binary from Git repository
The Git repository may be cloned as following:
```bash
$ git clone git@github.com:airsim/rmol.git rmolgit # through SSH
$ git clone https://github.com/airsim/rmol.git # if the firewall filters SSH
$ cd rmolgit
```
Then, you need the following packages (Fedora/RedHat/CentOS names here, 
but names may vary according to distributions):
* `cmake`
* `gcc-c++`
* `boost-devel` / `libboost-dev`
* `python-devel` / `python-dev`
* `gettext-devel` / `gettext`
* `sqlite3-devel` / `libsqlite3-dev`
* `readline-devel` / `libreadline-dev`
* `libncurses5-devel`
* `soci-mysql-devel`, `soci-sqlite3-devel`
* `stdair-devel` / `libstdair-dev`
* `airrac-devel` / `libairrac-dev`
* `doxygen`, `ghostscript`, `graphviz`
* `tetex-latex` (optional)
* `rpm-build` (optional)
## Building the library and test binary from the tarball
The latest stable source tarball (`rmol*.tar.gz` or `.bz2`) can be
found on GitHub: http://github.com/airsim/rmol/releases, _e.g._,
https://github.com/airsim/rmol/archive/rmol-1.00.6.tar.gz
As RMOL depends on other
[Travel Market Simulator (TvlSim/AirSim)](https://github.com/airsim/)
modules, more specifically [StdAir](https://github.com/airsim/stdair)
and [AirRAC](https://github.com/airsim/airrac), it may be
convenient to use the
[MetaSim project](https://github.com/airsim/metasim),
which pulls at once all the components of TvlSim in the same place,
and then orchestrates the dependencies for the builds, installations
and use of components.
If MetaSim is not used, in order to customise the following to your
environment, you can alter the path to the installation directory:
```bash
export INSTALL_BASEDIR="${HOME}/dev/deliveries"
export RMOL_VER="1.00.6"
if [ -d /usr/lib64 ]; then LIBSUFFIX="64"; fi
export LIBSUFFIX_4_CMAKE="-DLIB_SUFFIX=$LIBSUFFIX"
```
Then, as usual:
* To configure the project, type something like:
```bash
  mkdir build && cd build
  cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_BASEDIR}/rmol-$RMOL_VER \
   -DWITH_STDAIR_PREFIX=${INSTALL_BASEDIR}/stdair-stable \
   -DWITH_AIRRAC_PREFIX=${INSTALL_BASEDIR}/airrac-stable \
   -DCMAKE_BUILD_TYPE:STRING=Debug -DENABLE_TEST:BOOL=ON -DINSTALL_DOC:BOOL=ON \
   -DRUN_GCOV:BOOL=OFF ${LIBSUFFIX_4_CMAKE} ..
   ${LIBSUFFIX_4_CMAKE} ..
```
* To build the project, type:
```bash
  make
```
* To test the project, type:
```bash
  make check
```
* To install the library (`librmol*.so*`) and the binary (`rmol`),
```bash
  make install
  cd ${INSTALL_BASEDIR}
  rm -f rmol-stable && ln -s rmol-${RMOL_VER} rmol-stable
  cd -
```
* To package the source files, type:
```bash
  make dist
```
* To package the binary and the (HTML and PDF) documentation:
```bash
  make package
```
* To browse the (just installed, if enabled) HTML documentation:
```bash
  open file://${INSTALL_BASEDIR}/rmol-${RMOL_VER}/share/doc/rmol/html/index.html
```
* To browse the (just installed, if enabled) PDF documentation:
```bash
  open ${INSTALL_BASEDIR}/rmol-${RMOL_VER}/share/doc/rmol/html/refman.pdf
```
* To run the local binary version:
```
  ./rmol/rmol -b
```
* To run the installed version:
```bash
  ${INSTALL_BASEDIR}/rmol-$RMOL_VER/bin/rmol -b
```
# Python extension
The way to interact with a C++-based Python extension is extensively described
in the [OpenTREP project](https://github.com/trep/opentrep).
Only a quick start is given here.
## Python dependencies
* Install Python dependencies:
```bash
$ python3 -m pip install -U pip
$ python3 -m pip install -U wheel
$ python3 -m pip install -U build setuptools scikit-build tox pytest sphinx twine
```
## Build the Python extension
* Build the Python extension with SciKit-Build:
```bash
$ rm -rf _skbuild/ dist/ MANIFEST_
$ python3 setup.py --build-type=Debug build sdist bdist_wheel
```
* The Python artifacts should be similar to:
```bash
$ ls -lFh dist/
total 5872
-rw-r--r-- 1 user staff 2.0M Jun  1 15:49 rmol-1.0.5.post1-cp38-cp38-macosx_10_15_x86_64.whl
-rw-r--r-- 1 user staff 834K Jun  1 15:49 rmol-1.0.5.post1.tar.gz
```
* Updload the RMOL Python extension onto PyPi:
```bash
$ twine upload -u __token__ --repository-url https://upload.pypi.org/legacy/ dist/*
```
* The RMOL Python artifacts may then be browsed on PyyPI:
  https://pypi.org/project/rmol/
## Use the Python extension
* Launch the Python interpreter:
```bash
$ export PYTHONPATH=${PWD}/_skbuild/macosx-10.15-x86_64-3.8/cmake-install/lib:${PWD}/_skbuild/macosx-10.15-x86_64-3.8/cmake-install/lib/python3.8/site-packages/pyrmol
$ DYLD_INSERT_LIBRARIES=/Library/Developer/CommandLineTools/usr/lib/clang/11.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib ASAN_OPTIONS=detect_container_overflow=0 /usr/local/Cellar/python@3.8/3.8.3/Frameworks/Python.framework/Versions/3.8/Resources/Python.app/Contents/MacOS/Python
```
* Within the Python interpreter, import, initialize
  and use the RMOL Python extension:
```python
Python 3.8.3 (default, May 27 2020, 20:54:22) 
[Clang 11.0.3 (clang-1103.0.32.59)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyrmol
>>> rmolLibrary = pyrmol.RMOLer()
>>> rmolLibrary.init('rmol.log', 40, 1, '')
True
>>> rmolLibrary.rmol(100, 10, 40.0)
'RMOL has completed the generation of the booking requests. See the log file for more details.\n'
>>> quit()
```
* Back to the Shell session, look for the results in the RMOL log file:
```bash
$ cat rmol.log
Python wrapper initialisation
[D]${STDAIR_PREFIX}/stdair/command/CmdBomManager.cpp:52: StdAir is building the BOM tree from built-in specifications.
Python wrapper initialised
Optimisation for 100 draws, capacity of 40, and with the following method: 10
[D]${RMOL_PREFIX}/rmol/service/RMOL_Service.cpp:491: Optimisation by Monte-Carlo performed in 0.000321
[D]${RMOL_PREFIX}/rmol/service/RMOL_Service.cpp:492: Result: 
Yield: 100.00, Protection: 70.48, Booking limit: 100.00
Yield: 70.00, Protection: 156.19, Booking limit: 29.52
Yield: 42.00, Protection: -0.00, Booking limit: -56.19
[D]${RMOL_PREFIX}/rmol/service/RMOL_Service.cpp:505: Bid-Price Vector (BPV): 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 99.00, 99.00, 99.00, 99.00, 99.00, 98.00, 98.00, 97.00, 96.00, 96.00, 96.00, 96.00, 96.00, 95.00, 94.00, 94.00, 90.00, 90.00, 89.00, 88.00, 86.00, 84.00, 82.00, 80.00, 80.00, 79.00, 77.00, 76.00, 75.00, 72.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00, 70.00
End of the optimisation.
RMOL output: 
```
* Of course, a few more features could be added to the Python extension API,
  in order not to have to leave the Python interpreter to interact with the
  results of invoking the optimizer. Do not hesitate to contribute
  through [Pull Requests](https://github.com/airsim/rmol/pulls), which are
  always welcome!

%prep
%autosetup -n rmol-1.0.6.post1

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-rmol -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Fri Apr 07 2023 Python_Bot <Python_Bot@openeuler.org> - 1.0.6.post1-1
- Package Spec generated