Metadata-Version: 2.4
Name: dega2
Version: 0.1.0
Summary: DEGA-2: A optimization a function over the efficient set of  multi-objective  integer variables using the genetics algorithms
Author-email: Ali Zaidi <a.zaidi@crlca.dz>
License-Expression: MIT
Keywords: optimization,genetic algorithm,multi-objective,integer programming
Classifier: Programming Language :: Python :: 3
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Mathematics
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: tqdm
Provides-Extra: plot
Requires-Dist: matplotlib; extra == "plot"
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Dynamic: license-file

# DEGA-2

A optimisation of function over the efficient set of multi-objective  integer variables using a genetics algorithms, by Ali Zaidi.

It minimizes a function `phi·x` subject to linear constraints `a·x <= b`
(`x` integer, and `x >= 0` by default), using `p` objectives `c·x` for the
non-dominance test.

## Installation

```bash
pip install dega2
# with the convergence plot:
pip install "dega2[plot]"
```

## Entering your problem and parameters

### 1. Interactive assistant

```bash
dega2
```

The assistant asks for the problem (file, keyboard entry, or a random example),
then for the parameters (population size, alpha, number of explored variables,
iterations, `x >= 0` constraints). Press Enter to accept the suggested value.

### 2. `.json` file

```bash
dega2 --exemple my_problem.json     # writes a template to edit
dega2 -f my_problem.json            # runs the computation
```

File format:

```json
{
  "a": [[2, 3, 1], [1, 1, 2]],
  "b": [20, 15],
  "c": [[3, -1, 2], [-2, 4, 1]],
  "phi": [-3, -2, -4],
  "parametres": {
    "n_population": 20, "alpha": 4, "explor": 3,
    "iterations": 10, "positivity": true
  }
}
```

- `a`: constraint matrix (m rows, n columns); `b`: right-hand side (m values)
- `c`: objectives matrix (p rows, n columns); `phi`: function to minimize (n values)
- `parametres` is optional. Command-line options (`--population`, `--alpha`,
  `--explor`, `-T`, `--sans-positivite`, `--seed`, `--no-plot`) take precedence over
  the file. A `.npz` file (keys `a`, `b`, `c`, `phi`) is also accepted.

### 3. In Python code

```python
import numpy as np
import dega2

a   = np.array([[2, 3, 1], [1, 1, 2]])
b   = np.array([20, 15])
c   = np.array([[3, -1, 2], [-2, 4, 1]])
phi = np.array([-3, -2, -4])

res = dega2.solve(a, b, c, phi, n_population=20, explor=3, iterations=10, seed=0)

print(res.phi)      # best value of phi
print(res.x)        # best solution
res.plot()          # convergence curve (requires matplotlib)

# or from a file:
a, b, c, phi, params = dega2.charger_probleme("my_problem.json")
res = dega2.solve(a, b, c, phi, **params)
```

`solve` parameters: `n_population=80`, `alpha=4`, `explor=3`,
`iterations=None` (2·n by default), `positivity=True`, `seed=None`, `verbose=True`.
`solve` returns a `Result` object: `x`, `phi`, `history` (minimum of phi at each
iteration), `population`, `time`, `iterations`.

Note: the algorithm builds a population of `n_population` feasible solutions that
are mutually non-dominated. With very few objectives or variables, such a
population may not exist; `dega2` then stops with an error message (reduce
`n_population` or add objectives).

## Random demonstration

```bash
dega2 --demo --seed 1
dega2 --demo -n 20 -p 5 --no-plot
```

## Tests

```bash
pip install -e ".[test]"
pytest
```
