Skip to content

Commit

Permalink
Development (#2)
Browse files Browse the repository at this point in the history
* Initial Commit

* Adapted the readme.md and moved the main class to be executable with exec-maven plugin

* Adapted project information

* Update README.md

* Title correction

* Deleted previous versions

* Added reference to the data sets
  • Loading branch information
sgirardin authored Jun 11, 2020
1 parent 25a4698 commit 6e9e877
Show file tree
Hide file tree
Showing 66 changed files with 1,254 additions and 3,800 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ nb-configuration.xml
##############################
## OS X
##############################
.DS_Store
.DS_Store
/NSGA-II-report-*.txt
85 changes: 32 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,32 @@
# NSGA-II
**an NSGA-II implementation using Java**

**_Original Authors of the Paper_: [Kalyanmoy Deb](http://www.egr.msu.edu/~kdeb/), [Amrit Pratap](https://scholar.google.com/citations?user=E8wJ7G8AAAAJ&hl=en), [Sameer Agarwal](http://ieeexplore.ieee.org/search/searchresult.jsp?searchWithin=%22Authors%22:.QT.S.%20Agarwal.QT.&newsearch=true), [T. Meyarivan](http://ieeexplore.ieee.org/search/searchresult.jsp?searchWithin=%22Authors%22:.QT.T.%20Meyarivan.QT.&newsearch=true)**

_links to original contents:_

* [NSGA-II paper: PDF](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.542.385&rep=rep1&type=pdf)
* [NSGA-II code implementation by original authors at **KanGAL**](https://www.iitk.ac.in/kangal/codes.shtml)

_**note**: this implementation of NSGA-II algorithm is in pure reference to the original published paper. This is not an effort to convert the originally implemented C code in Java. The original C code by the authors has not be referred to while writing this implementation._

_**Dependency: Java( >= 13), JFreeChart(1.5.0), JCommon(1.0.24)**_

### Please Note:

This is **v3** of the algorithm implementation. This reference implementation has been updated to be:

* Used as package.
* Much more generic, customizable and hence more powerful.
* More efficient than the previous version.

The reference **v2** implementation can be found [here](https://github.com/onclave/NSGA-II/tree/master/v2). The _README_ of that implementation can be found [here](https://github.com/onclave/NSGA-II/blob/master/v2/README.md).

The reference **v1** implementation can be found [here](https://github.com/onclave/NSGA-II/tree/master/v1). The _README_ of that implementation can be found [here](https://github.com/onclave/NSGA-II/blob/master/v1/README.md).

**note:** Code commenting of **v3** is under progress and not all code is commented properly. This shall be done shortly. In the mean time, if you are unable to understand any part of the code, feel free to open an _issue_ about it and I shall try to
resolve it.

### Documentation

This is a fully customizable implementation of the NSGA-II algorithm, made as generic as possible. This documentation assumes you have basic understanding of the NSGA-II algorithm. Apart from the core concepts of the algorithm, everything else in this
package can be implemented as per the user's choice and plugged into the algorithm dynamically.

By default, the package provides a default implementation of every plugin and hence the package can be run with just one line of code as a PoC.

```java
(new NSGA2()).run();
```

For more information, visit the [Wiki](https://github.com/onclave/NSGA-II/wiki)

For full documentation, visit the [Documentation Wiki](https://github.com/onclave/NSGA-II/wiki/Documentation).

### Using it in your project

This package shall be published to maven shortly. Till then you can use the source package directly in your project.

### [Getting Started](https://github.com/onclave/NSGA-II/wiki/Getting-Started)

### Contributing

This project is open to pull requests and encourages new features through contribution. The contribution guidelines shall be updated shortly.
# Train rostering using NSGA-II
**an NSGA-II implementation for assigning randomly Train Services to train crews**

**Original implementation of the algorithm: [here](https://github.com/onclave/NSGA-II) v3.0.1**
**Original readme.md [here](https://github.com/sgirardin/NSGA-II/wiki/Original-readme.md)**

## Installation
You will need:
1. Have Java >= 13
1. Maven 3+
1. Then clone the repository locally

## How to run
### With your favorite IDE (prefered way)
1. Run the main class ```NSGA2Test.java```

### Command line
1. Go in project root folder with a terminal
2. Run ```mvn install -Dgpg.skip exec:java```
3. Do modification in the configuration and do the command at point above.

## Configuration
In the ```NSGA2Test:main``` method you can change the following parameters:
1. Population size
2. Number of generations
3. Mutation probability
4. Which crossover operator (for the moment we have UniformCrossover or OnePointMutation)
5. Size of Train Crew against which 63 Services will be distributed

## Data sets
* ```ch.fhnw.mbis.aci.nsgaii.sets.models.TrainService.java``` for the train services
* ```ch.fhnw.mbis.aci.nsgaii.sets.models.TrainCrew.java ```for the train drivers
85 changes: 31 additions & 54 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,11 @@

<name>NSGA-II</name>

<parent>
<artifactId>oss-parent</artifactId>
<groupId>org.sonatype.oss</groupId>
<version>9</version>
</parent>

<groupId>com.debacharya</groupId>
<groupId>ch.fhnw.aci</groupId>
<artifactId>nsgaii</artifactId>
<version>3.0.1</version>
<version>1.0.0</version>
<packaging>jar</packaging>

<inceptionYear>2019</inceptionYear>
<url>https://debacharya.com/nsgaii</url>

<description>
A NSGA-II implementation using Java. This implementation of NSGA-II algorithm is in pure reference to the
original published paper. This is not an effort to convert the originally implemented C code in Java.
The original C code by the authors has not be referred to while writing this implementation.
This is a fully customizable implementation of the NSGA-II algorithm, made as generic as possible.
This documentation assumes you have basic understanding of the NSGA-II algorithm. Apart from the core concepts
of the algorithm, everything else in this package can be implemented as per the user's choice and plugged
into the algorithm dynamically. Since NSGA-II is more like a set of protocols to follow as an algorithm rather
than a concrete implementation of every aspect, this package has been re-written from scratch keeping complete
customizability in mind. Apart from the core concepts of the algorithm, everything is considered to be a plugin
external to the algorithm that can be implemented by the user and dynamically plugged into the algorithm during
runtime as needed. This opens up the possibility of the package to be used simply as a PoC or be converted into
something much more complex according to the users needs.
</description>

<issueManagement>
<url>https://github.com/onclave/NSGA-II/issues</url>
<system>GitHub Issues</system>
</issueManagement>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
</repository>
</distributionManagement>

<scm>
<connection>scm:git:git:https://github.com/onclave/NSGA-II.git</connection>
<url>https://github.com/onclave/NSGA-II</url>
</scm>

<developers>
<developer>
<name>Debabrata Acharya</name>
<email>debabrata@bloomscorp.com</email>
</developer>
</developers>

<licenses>
<license>
<name>MIT License</name>
Expand All @@ -81,6 +29,19 @@
<artifactId>jcommon</artifactId>
<version>1.0.24</version>
</dependency>

<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down Expand Up @@ -148,6 +109,22 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>13</source>
<target>13</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<mainClass>NSGA2Test</mainClass>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
40 changes: 40 additions & 0 deletions src/main/java/NSGA2Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import ch.fhnw.mbis.aci.nsgaii.plugin.OnePointCrossover;
import ch.fhnw.mbis.aci.nsgaii.plugin.SchedulingPluginProvider;
import ch.fhnw.mbis.aci.nsgaii.population.TrainCrewSet;
import ch.fhnw.mbis.aci.nsgaii.population.TrainServiceSet;
import ch.fhnw.mbis.aci.nsgaii.sets.models.enums.TrainCrewPopulationSize;
import com.debacharya.nsgaii.Configuration;
import com.debacharya.nsgaii.NSGA2;
import com.debacharya.nsgaii.datastructure.Population;
import com.debacharya.nsgaii.plugin.CrossoverParticipantCreatorProvider;
import com.debacharya.nsgaii.plugin.PopulationProducer;
import com.debacharya.nsgaii.plugin.SinglePointMutation;
import com.debacharya.nsgaii.plugin.UniformCrossover;

public class NSGA2Test {

public static void main(String[] args) {
// Set parameters
int populationSize = 3;
int nbGenerations = 1;
float mutationProbability = 0.4f;
TrainCrewPopulationSize crewPopulationSize = TrainCrewPopulationSize.TWENTY;

//Implemented Mutations and crossovers
UniformCrossover uniformCrossover = new UniformCrossover(CrossoverParticipantCreatorProvider.selectByBinaryTournamentSelection());
OnePointCrossover onePointCrossover = new OnePointCrossover(CrossoverParticipantCreatorProvider.selectByBinaryTournamentSelection());
SinglePointMutation singlePointMutation = new SinglePointMutation(mutationProbability);


//Initialize Population sets
TrainServiceSet.setupServiceSet();
TrainCrewSet.setupPopulation(crewPopulationSize);

PopulationProducer populationProducer = SchedulingPluginProvider.defaultPopulationProducer();

Configuration configuration = new Configuration(populationSize,nbGenerations, populationProducer, uniformCrossover, singlePointMutation);

NSGA2 nsga2 = new NSGA2(configuration);
Population paretoFront = nsga2.run();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ch.fhnw.mbis.aci.nsgaii.datastructure;

import com.debacharya.nsgaii.datastructure.AbstractAllele;

public class IntegerAllele extends AbstractAllele {

public IntegerAllele(Integer gene) {
super(gene);
}

@Override
public Integer getAllele() {
return (int) this.allele;
}

@Override
public IntegerAllele getCopy() {
return new IntegerAllele((Integer)this.allele);
}

@Override
public String toString() {
return "IntegerAllele{" +
"gene=" + allele +
'}';
}
}
Loading

0 comments on commit 6e9e877

Please sign in to comment.