tuto_ecj_android
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tuto_ecj_android [2014/03/03 14:10] – [3. Add ECJ library in your project] Denis Pallez | tuto_ecj_android [2014/03/03 16:27] (current) – Denis Pallez | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
- | + | ||
- | - [[# | + | |
- | - [[# | + | |
- | - [[# | + | |
- | - [[# | + | |
- | - [[# | + | |
- | - [[# | + | |
- | - [[# | + | |
===== 1. Installation of Eclispe and Android SDK ===== | ===== 1. Installation of Eclispe and Android SDK ===== | ||
First of all, to make the development of Android app easier, you have to install the Eclipse framework. In this environment, | First of all, to make the development of Android app easier, you have to install the Eclipse framework. In this environment, | ||
- | |||
- | [[# | ||
===== 2. Create a new Android Project ===== | ===== 2. Create a new Android Project ===== | ||
Line 19: | Line 8: | ||
When the two first steps are done, we will create a new Android project with eclipse. < | When the two first steps are done, we will create a new Android project with eclipse. < | ||
- In your workspace, your new project should be as shown below :</ | - In your workspace, your new project should be as shown below :</ | ||
- | |||
- | [[# | ||
===== 3. Add ECJ library in your project ===== | ===== 3. Add ECJ library in your project ===== | ||
Line 37: | Line 24: | ||
- Right click on this new package -> new -> File | - Right click on this new package -> new -> File | ||
- Name the new file " | - Name the new file " | ||
- | |||
- | [[# | ||
===== 4. Collect configuration data ===== | ===== 4. Collect configuration data ===== | ||
- | Now, to get the all data in " | + | Now, to get the all data in " |
+ | <code java> | ||
+ | InputStream configStream = null; | ||
+ | try { | ||
+ | | ||
+ | | ||
+ | } | ||
+ | catch (IOException e) { | ||
+ | | ||
+ | } | ||
+ | </ | ||
- | If your configuration file is named " | + | If your configuration file is named " |
+ | It only remains to transfer the InputStream " | ||
+ | <code java> | ||
+ | ParameterDatabase paramDB = null; | ||
+ | try { | ||
+ | | ||
+ | } | ||
+ | catch (IOException e) { | ||
+ | | ||
+ | } | ||
+ | </code> | ||
- | [[# | + | Now, you could run your evolutionary algorithm with the code below (more details are given in the ECJ manual, page 44) |
+ | <code java> | ||
+ | EvolutionState evaluatedState = Evolve.initialize(paramDB, | ||
+ | evaluatedState.startFresh(); | ||
+ | int result = EvolutionState.R_NOTDONE; | ||
+ | while( result == EvolutionState.R_NOTDONE ) | ||
+ | result = evaluatedState.evolve(); | ||
+ | </ | ||
===== 5. Print configuration data ===== | ===== 5. Print configuration data ===== | ||
- | If you want to be convinced that your configurations are in the InputStream, | + | If you want to be convinced that your configurations are in the InputStream, |
- | + | <code java> | |
- | [[# | + | String out = ""; |
+ | try{ | ||
+ | | ||
+ | | ||
+ | | ||
+ | while ( (ligne=br.readLine()) != null) { | ||
+ | | ||
+ | } | ||
+ | | ||
+ | } | ||
+ | catch (Exception e) { | ||
+ | | ||
+ | } | ||
+ | System.out.println(" | ||
+ | </ | ||
+ | \\ {{ECJ_Android_fichiers: | ||
===== 6. Write in a File with Android ===== | ===== 6. Write in a File with Android ===== | ||
- | However, ECJ may need a real File to run, and not an InputStream. For example, to initialize a population.\\ \\ In this part we'll see how to write a file.\\ As in the previous example you'll need a package named " | + | However, ECJ may need a real File to run, and not an InputStream. For example, to initialize a population. |
+ | |||
+ | In this part we'll see how to write a file. | ||
+ | As in the previous example you'll need a package named " | ||
+ | After, you'll need the context of you application : <code java>Context mContext = this; </ | ||
+ | Then, you have to load your file on your smartphone : <code java>File file = mContext.getFileStreamPath(" | ||
+ | Finaly, you can write into your file thanks to a FileWrite and a BufferedWriter : <code java> | ||
+ | FileWriter fileWriter = null; | ||
+ | try { | ||
+ | | ||
+ | } | ||
+ | catch (IOException e1) { | ||
+ | | ||
+ | } | ||
+ | BufferedWriter output = new BufferedWriter(fileWriter); | ||
+ | try { | ||
+ | | ||
+ | } | ||
+ | output.flush(); | ||
+ | catch (Exception e) { | ||
+ | | ||
+ | } | ||
+ | finally { | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
- | [[# | + | As you can understand, this code write the text "Hello World" into the file " |
===== 7. Use a file in an another one ===== | ===== 7. Use a file in an another one ===== | ||
Line 64: | Line 122: | ||
Now, you can use this file as in the previous [[# | Now, you can use this file as in the previous [[# | ||
- | But, as we said before, ECJ may need a file. Or more precisely, the path of this file.\\ For a population initialization, | + | But, as we said before, ECJ may need a file. Or more precisely, the path of this file.\\ For a population initialization, |
- | + | < | |
- | [[# | + | pop.file = / |
+ | </ | ||
+ | Now, if you load " | ||
Any questions or suggestions ? [[guegan@polytech.unice.fr; | Any questions or suggestions ? [[guegan@polytech.unice.fr; | ||
+ | |||
+ | < | ||
+ |
tuto_ecj_android.1393855807.txt.gz · Last modified: 2014/03/03 14:10 by Denis Pallez