diff --git a/README.md b/README.md index 999f542..1297373 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,13 @@ -# Duelist-Algorithm-Python [![Build Status](https://travis-ci.com/tsyet12/Duelist-Algorithm-Python.svg?branch=master)](https://travis-ci.com/tsyet12/Duelist-Algorithm-Python) ![PyPI](https://img.shields.io/pypi/v/DuelistAlgorithmPython.svg) +# Duelist-Algorithm-Python [![Build Status](https://travis-ci.com/tsyet12/Duelist-Algorithm-Python.svg?branch=master)](https://travis-ci.com/tsyet12/Duelist-Algorithm-Python) ![PyPI](https://img.shields.io/pypi/v/DuelistAlgorithmPython.svg) ![Python Version](https://img.shields.io/badge/Python-3.4%20%7C%203.5%20%7C%203.6%20%7C%203.7-brightgreen.svg) A Python implementation of the paper : Duelist Algorithm: An Algorithm Inspired by How Duelist Improve Their Capabilities in a Duel (2015) Totok Ruki Biyanto, Henokh Yernias Fibrianto, Gunawan Nugroho, Erny Listijorini, Titik Budiati, Hairul Huda https://arxiv.org/abs/1512.00708 + + + +This implementation only uses numpy, which is mainly written in C for fast computational speed. + I would like to clarify that various figures of this README.md document is taken from the original artical as shown above. @@ -32,14 +37,20 @@ In the original paper, Duelist Algorithm was shown to out-perform a few state-of # Dependencies This algorithm is fully implemented in Python. It is recommended to use Python 3.X. Library dependencies: - numpy 1.15.4 +- matplotlib ```BASH -$ pip install numpy +$ pip install numpy matplotlib ``` # How to Use + +You can use two methods for installation: + +**1. Install from github (recommended as this will download the newest version)** + First download the git repository. You can do this by clicking the download button or using the git command: ```BASH $ git pull https://github.com/tsyet12/Duelist-Algorithm-Python @@ -64,6 +75,23 @@ Move to examples and run the examples $ cd examples ``` +**1. Install from pip ** + +You can install this package from pip. + +Linux: + +```BASH +$ pip install DuelistAlgorithmPython +``` + +Windows: + +```BASH +$ python -m pip install DuelistAlgorithmPython +``` + + # Short Tutorial **There are four simple steps to run an optimization problem using Duelist Algorithm** @@ -124,7 +152,7 @@ From the console we can deduce the optimal result (see Fig. 4) . The global opti ![result1](images/results.PNG) -*Fig 4. Optimal Results in Console* +*Fig 4. Optimal Results in Console (Colour may vary according to your environment)* We can see that the algorithm quickly converges to the optimal point (see Fig. 5) as reported by the original article. Note that graph is decreasing instead of increasing (in the case of original paper) because our objective is to MINIMIZE instead of maximizing. You can just add a negative sign in the function to get maximization. @@ -135,16 +163,50 @@ We can see that the algorithm quickly converges to the optimal point (see Fig. 5 For more examples refer to the python scripts in "examples" folder. [https://github.com/tsyet12/Duelist-Algorithm-Python/tree/master/examples] -# Small Tutorial on Complex Constraint using Karush-Kuhn-Tucker (KKT) conditions +# Dealing with Complex Constraint conditions There will be some problems that have complex constraints. For example, constraints which depends on two or more manipulated variables. -Say: we take the same problem from the **Short Tutorial**, and now we have an extra constraint, which is x1 must be larger than x2: +*Example 1: Inequality* + +Say: +We take the same problem from the **Short Tutorial**, and now we have an extra constraint, which is x1 must be larger than x2: + > x1>x2 -Using KKT conditions, we can put this constraint in the objective function: +We can put this constraint in the objective function: + +f=(x1,x2) = (x1)^2+(x2)^2 + max(0,x2-x1) + +Implementation: + +```python +def f(x1,x2): + return x1*x1+x2*x2+max(0,x2-x1) +``` +Continue from Step 2 of **Short Tutorial**. + + + +*Example 2: Equality* + +Say: +We take the same problem from the **Short Tutorial**, and now the extra constraint is x1 equal to x2: + +> x1=x2 + +We can put this constraint in the objective function: + +f=(x1,x2) = (x1)^2+(x2)^2 + (x2-x1)^2 + +Implementation: + +```python +def f(x1,x2): + return x1*x1+x2*x2+(x2-x1)*(x2-x1) +``` -f=(x1,x2) = (x1)^2+(x2)^2 + ( +Continue from Step 2 of **Short Tutorial**. # Version diff --git a/requirements.txt b/requirements.txt index 3e566f4..aa094d9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -numpy==1.15.4 -matplotlib \ No newline at end of file +numpy +matplotlib