You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+25-65Lines changed: 25 additions & 65 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,47 +11,6 @@ We also include an implementation of R-SPLINE, which can be cited as follows:
11
11
12
12
Wang, H., Pasupathy, R., and Schmeiser, B. W. 2013. Integer-ordered simulation optimization using R-SPLINE: Retrospective Search with Piecewise-Linear Interpolation and Neighborhood Enumeration. ACM Transactions on Modeling and Computer Simulation, Vol. 23, No. 3, Article 17 (July 2013), 24 pages. DOI:http://dx.doi.org/10.1145/2499913.2499916
* [Install latest trunk version from git](#install-latest-trunk-version-from-git)
24
-
* [Install from source](#install-from-source)
25
-
* [CLI](#cli)
26
-
* [CLI: listitems](#cli-listitems)
27
-
* [CLI: solve](#cli-solve)
28
-
* [CLI: testsolve](#cli-testsolve)
29
-
* [CLI: Output](#cli-output)
30
-
* [Table of options for solve and testsolve](#table-of-options-for-solve-and-testsolve)
31
-
* [Table of algorithm-specific parameters](#table-of-algorithm-specific-parameters)
32
-
* [Programming guide](#programming-guide)
33
-
* [Implementing a problem in PyMOSO](#implementing-a-problem-in-pymoso)
34
-
* [Template for implementing problems (myproblem.py)](#template-for-implementing-problems-myproblempy)
35
-
* [Using rng](#using-rng)
36
-
* [Simple example problem](#simple-example-problem)
37
-
* [Implementing a Tester in PyMOSO](#implementing-a-tester-in-pymoso)
38
-
* [Implementing algorithms in PyMOSO](#implementing-algorithms-in-pymoso)
39
-
* [Example MOSO algorithm in PyMOSO that uses RLE to ensure convergence (myaccel.py)](#example-moso-algorithm-in-pymoso-that-uses-rle-to-ensure-convergence-myaccelpy)
40
-
* [Example of an RA algorithm (myraalg.py)](#example-of-an-ra-algorithm-myraalgpy)
41
-
* [Example of a MOSO algorithm (mymoso.py)](#example-of-a-moso-algorithm-mymosopy)
42
-
* [Class Structure and internal functions](#class-structure-and-internal-functions)
43
-
* [Useful snippets for implementing RA algorithms](#useful-snippets-for-implementing-ra-algorithms)
44
-
* [Sample a point](#sample-a-point)
45
-
* [Sample the point's neighbors](#sample-the-points-neighbors)
46
-
* [argsort the points by 1st objective](#argsort-the-points-by-1st-objective)
47
-
* [choose the minimizer and its objectives](#choose-the-minimizer-and-its-objectives)
48
-
* [Use SPLINE to get a local minimizer](#use-spline-to-get-a-local-minimizer)
49
-
* [Get the non-dominated subset of every visited point](#get-the-non-dominated-subset-of-every-visited-point)
50
-
* [Randomly choose points from the subset](#randomly-choose-points-from-the-subset)
51
-
* [Using PyMOSO in Python programs](#using-pymoso-in-python-programs)
52
-
* [Solve example](#solve-example)
53
-
* [TestSolve example](#testsolve-example)
54
-
55
14
## Installation
56
15
### Dependency: Python 3.6+
57
16
This software requires Python 3.6 or higher. Python can be downloaded from https://www.python.org/downloads/.
@@ -117,19 +76,19 @@ Help:
117
76
test problems.
118
77
```
119
78
For now, PyMOSO has three commands: `listitems`, `solve`, and `testsolve`, which we explain below.
120
-
##### CLI: listitems
79
+
#### listitems
121
80
The command `listitems` shows the PyMOSO objects (problems, testers, solvers) included in the default installation. The identifiers can be used as arguments to `solve` and `testsolve`. PyMOSO objects implemented by users will not show up when using `listitems`.
122
-
##### CLI: solve
81
+
#### solve
123
82
The `solve` command is intended for practitioners seeking to a solve a simulation optimization problem. Three arguments are required: `<problem>`, `<solver>`, and `<x>...`. For `<problem>`, users may specify an identifier for a built-in problem. A list of such identifiers can be viewed using `listitems`. Alternatively, users may implement their own problem as a PyMOSO oracle (see the code examples below) and specify the file name.
124
83
For example,
125
84
`pymoso solve myproblem.py RPERLE 40 40`
126
85
The `<solver>` argument again either an identifier to a built-in algorithm, or a file name for a user-implemented algorithm. The `<x>...` is a feasible starting point for the algorithm, with each component of the starting point separated by a space. Any number of the options listed above can also be specified before the arguments. At the end of this section, we list the options and provide more detailed explanations. The `<x>` argument cannot take negative numbers from the command line. Use PyMOSO in a Python program if a negative starting point is required (see examples below).
127
-
##### CLI: testsolve
86
+
#### testsolve
128
87
The `testsolve` command is intended for researchers creating new simulation optimization algorithms. Two arguments are required: `<tester>` and `<solver>`. Similar to `solve`, `<tester>` and `<solver>` may be specified as identifiers to built-in testers or as Python files containing user-implemented objects. Specifying `<x>...` is optional: testers may implement a method to generate feasible starting points. If not, then `<x>...` can be provided.
129
-
##### CLI: Output
88
+
#### Output
130
89
Both `solve` and `testsolve` create a subdirectory within the working directory in which the generated results are saved. In the case of `solve`, the directory typically contains two files: a file containing metadata such as the arguments and options specified, date, run time, and more. The second file contains the solution generated by the chosen solver. If applicable, an error file may be generated. If an error is generated, users may send the metadata file, the error file, and any user-implemented PyMOSO objects to us for assistance. In the case of `testsolve`, the file containing the solution will instead contain multiple solutions, with the last row containing the end solution returned by the algorithm. The intermediate solutions are provided to give a researchers a sense of how the algorithm progresses. If the `--isp` option is specified to generate multiple independent sample path solutions, there will a solution file for every independent sample path. If the `--metric` options is specified, the metric defined in the `<tester>` will be computed on the solutions and saved in a separate file. All available options to `solve` or `testsolve` are specified below.
131
90
132
-
#####Table of options for solve and testsolve
91
+
#### Table of options for solve and testsolve
133
92
| Option | Description |
134
93
| ----------- | ----------- |
135
94
|`--budget=B`| The simulation budget limits the number of simulations the algorithm can use to generate a solution. `B` should be a natural number. |
@@ -143,7 +102,7 @@ Both `solve` and `testsolve` create a subdirectory within the working directory
143
102
|`--param <param> <val>`| Specify a parameter by name and value. These are algorithm-specific parameters.|
144
103
145
104
146
-
#####Table of algorithm-specific parameters
105
+
#### Table of algorithm-specific parameters
147
106
| Algorithm | Parameter | Default | Description |
148
107
| --------- | --------- | ------- | ----------- |
149
108
|`RPERLE`, `RMINRLE`, `RPE`, `RSPLINE`|`mconst`|`2`| Sets the initial sample size, and subsequent schedule of sample sizes. |
@@ -158,7 +117,7 @@ Users can implement their own problems in PyMOSO using `myproblem.py` below as t
158
117
1.`True` or `False` depending on if `x` is feasible to the problem.
159
118
1. A tuple of length `self.num_obj` containing the value of each objective.
160
119
161
-
#####Template for implementing problems (myproblem.py)
120
+
#### Template for implementing problems (myproblem.py)
162
121
```python
163
122
# import the Oracle base class
164
123
from pymoso.chnbase import Oracle
@@ -182,7 +141,7 @@ class MyProblem(Oracle):
182
141
return is_feas, (obj1, obj2)
183
142
```
184
143
185
-
#####Using `rng`
144
+
#### Using `rng`
186
145
Though not required, users may use the `rng` random number generator object. Doing so allows algorithms to take advantage of common random numbers and ensures parallelized simulation replications are independent. The implementation of the `rng` object is a subclass of Python's `random.Random()` where the underlying generator is `mrg32k3a`. Thus, Python's own `random` documentation applies to `rng` and can be found at https://docs.python.org/3/library/random.html. We follow the example of L'Ecuyer et al. 2001 for `mrg32k3a` and implementing its independent streams and substreams.
187
146
188
147
L'Ecuyer, P., Simard, R., Chen, E. J., Kelton, W. D. An Object-Oriented Random-Number Package with Many Long Streams and Substreams. (2002). Operations Research, 50(6), 1073-1075.
@@ -195,7 +154,7 @@ To be compatible with common random numbers, users can simply use the generator.
195
154
196
155
To ensure independent sampling of observations, PyMOSO "jumps" the stream after every observation by a fixed amount of `pow(2, 76)`. Thus, we require that every simulation observation use fewer than `pow(2, 76)` random numbers for users needing independent replications. We ensure independence among parallel replications by "giving" each processor an `rng` each of which are `pow(2, 127)` randomn numbers apart. When using the included algorithms, each retrospective iteration begins with a new independent stream `pow(2, 127)` from the beginning of the previous stream, where PyMOSO sets the previous stream to account for any parallel streams used within a retrospective iteration. thus, in a given retrospective iteration, a user may simulate 100 million points at a sample size of 1 million, without common random numbers, and easily not reach the limit. For researchers using `testsolve`, the observations cannot be taken in parallel, but independent algorithm instances can be. To ensure the instances remain independent, researchers should set the budget such that the included algorithms do not surpass 200 retrospective iterations. For reference, on default settings, the sample size at every point in the 200th iteration is almost 380 million.
197
156
198
-
#####Simple example problem
157
+
#### Simple example problem
199
158
```python
200
159
defg(self, x, rng):
201
160
'''Check feasibility and simulate objective values.'''
@@ -290,7 +249,7 @@ Users can leverage internal PyMOSO structures to implement new algorithms. It is
290
249
291
250
Pasupathy R, Ghosh S (2013) Simulation optimization: a concise overview and implementation guide. Topaloglu H, ed., TutORials in Operations Research, chapter 7, 122–150 (Catonsville, MD: INFORMS), URL http://dx.doi.org/10.1287/educ.2013.0118.
292
251
293
-
#####Example MOSO algorithm in PyMOSO that uses RLE to ensure convergence (myaccel.py)
252
+
#### Example MOSO algorithm in PyMOSO that uses RLE to ensure convergence (myaccel.py)
294
253
```python
295
254
from pymoso.chnbase import RLESolver
296
255
@@ -309,7 +268,7 @@ Programmers can use pymoso to create new algorithms that use RLE for convergence
309
268
Once implmented, solve a problem using the accelerator as follows.
310
269
`pymoso solve myproblem.py myaccel.py 97`
311
270
312
-
#####Example of an RA algorithm (myraalg.py)
271
+
#### Example of an RA algorithm (myraalg.py)
313
272
```python
314
273
from pymoso.chnbase import RASolver
315
274
@@ -327,7 +286,7 @@ More generally, algorithm designers can quickly implement any retrospective appr
327
286
328
287
`pymoso solve myproblem.py myraalg.py 97`
329
288
330
-
#####Example of a MOSO algorithm (mymoso.py)
289
+
#### Example of a MOSO algorithm (mymoso.py)
331
290
```python
332
291
from pymoso.chnbase import MOSOSolver
333
292
@@ -352,10 +311,11 @@ class MyMOSO(MOSOSolver):
352
311
353
312
PyMOSO can accommodate any simulation optimization algorithm by implementing the `solve` function of a `MOSOSolver` class as shown. It does not have to be a multi-objective algorithm. PyMOSO will require users to send an initial feasible point `x0` whether or not the algorithm needs it. It is accessed through `self.x0` which is a tuple. The return value must be a Python dictionary with the keys 'itersoln', 'simcalls', and 'endseed'. 'itersoln' itself is a dictionary with a key for every iteration (or a number indicating some ordered, intermediate step of the algorithm). Similarly, `simcalls` is itself a dictionary of iteration number by cumulative number of simulations at the end of the corresponding iteration. `endseed` is a tuple of length 6 representing a new indpendent `rng` seed users can pass into the next PyMOSO invocation.
354
313
355
-
##### Class Structure and internal functions
314
+
#### PyMOSO internals
356
315
The base class `MOSOSolver` implements basic members required to solve MOSO problems. To implement a general (i.e. non-RA) MOSO algorithm in pymoso, one must subclass `MOSOSolver` and implement the `MOSOSolver.solve` function with signature `solve(self, budget)` and it must return a set, even if the set contains a single point. `RASolver` is a subclass of `MOSOSolver` which provides the machinery needed to quickly implement a retrospective approximation algorithm. To implement an RA algorithm, one must subclass `RASolver` and implement its `spsolve` method with signature `spsolve(self, warm_start)` which returns a set of points.`RLESolver`, subclass of `RASolver`, allows quick implementation of MOSO solvers that use `RLE` to ensure convergence, as shown in the example accelerator above. One only needs to implement the `accel` method of `RLESolver`. Oracles are the problems that PyMOSO can solve. Here, we provide a listing of the important objects available to pymoso programmers who are implementing MOSO algorithms.
357
316
358
-
| PyMOSO internals | Example | Description |
317
+
##### Table of PyMOSO internals
318
+
| PyMOSO internal object | Example | Description |
359
319
| ------------- | ------- | ----------- |
360
320
|`pymoso.prng.mrg32k3a.MRG32k3a`| `rng = MRG32k3a()` | Subclass of `random.Random()` for generating random numbers. |
361
321
|`pymoso.prng.mrg32k3a.get_next_prnstream`| `prn = get_next_prnstream(seed)` | Returns a stream 2^127 places from the given `seed` |
@@ -389,7 +349,7 @@ The base class `MOSOSolver` implements basic members required to solve MOSO prob
389
349
|`RLESolver.betadel` | `bd = RLESolver.betadel` | The relaxation parameter used by `RLE`. |
390
350
|`RLESolver.calc_delta` | `d = RLESolver.calc_delta(nu)` | Compute the relaxation for iteration `nu`. |
391
351
392
-
352
+
##### Table of chnutils functions
393
353
| chnutils function | Example | Description |
394
354
| ------------- | ------- | ----------- |
395
355
|`does_weak_dominate` | `dwd = does_weak_dominate(g1, g2, rel1, rel2)` | Returns true if `g1[i] - rel1[i] <= g2[i] + rel2[i]` for every `i`.
@@ -400,9 +360,9 @@ The base class `MOSOSolver` implements basic members required to solve MOSO prob
400
360
|`get_nbors` | `nbors = get_nbors(x, r)` | Return the set of points no farther than `r` from `x` and exclude `x`. |
401
361
|`get_setnbors` | `nbors = get_setnbors(S, r)` | Excluding points in the set `S`, return `get_nbors(s, r)` for every `s` in `S`. |
402
362
403
-
##### Useful snippets for implementing RA algorithms
363
+
#### Useful snippets for implementing RA algorithms
404
364
These snippets will work within the `spsolve` and/or the `accel` functions in the `myaccel.py` and `myraalg.py` examples above.
405
-
###### Sample a point
365
+
##### Sample a point
406
366
```python
407
367
from pymoso.chnutils import get_nbors
408
368
# pretend x has not yet been visited in this RA iteration and is feasible
@@ -425,7 +385,7 @@ isfeas, fx, se = self.estimate(x)
0 commit comments