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:16] – [5. Print configuration data] 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 " | ||
- | < | + | < |
InputStream configStream = null; | InputStream configStream = null; | ||
try { | try { | ||
Line 56: | Line 41: | ||
If your configuration file is named " | If your configuration file is named " | ||
It only remains to transfer the InputStream " | It only remains to transfer the InputStream " | ||
- | < | + | < |
ParameterDatabase paramDB = null; | ParameterDatabase paramDB = null; | ||
try { | try { | ||
Line 67: | Line 52: | ||
Now, you could run your evolutionary algorithm with the code below (more details are given in the ECJ manual, page 44) | Now, you could run your evolutionary algorithm with the code below (more details are given in the ECJ manual, page 44) | ||
- | < | + | < |
EvolutionState evaluatedState = Evolve.initialize(paramDB, | EvolutionState evaluatedState = Evolve.initialize(paramDB, | ||
evaluatedState.startFresh(); | evaluatedState.startFresh(); | ||
Line 74: | Line 59: | ||
result = evaluatedState.evolve(); | result = evaluatedState.evolve(); | ||
</ | </ | ||
- | |||
- | [[# | ||
===== 5. Print configuration data ===== | ===== 5. Print configuration data ===== | ||
Line 97: | Line 80: | ||
</ | </ | ||
\\ {{ECJ_Android_fichiers: | \\ {{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> | ||
+ | Then, you have to load your file on your smartphone : <code java> | ||
+ | Finaly, you can write into your file thanks to a FileWrite and a BufferedWriter : <code java> | ||
+ | FileWriter fileWriter = null; | ||
+ | try { | ||
+ | fileWriter = new FileWriter(file); | ||
+ | } | ||
+ | catch (IOException e1) { | ||
+ | e1.printStackTrace(); | ||
+ | } | ||
+ | BufferedWriter output = new BufferedWriter(fileWriter); | ||
+ | try { | ||
+ | output.write(" | ||
+ | } | ||
+ | output.flush(); | ||
+ | catch (Exception e) { | ||
+ | Toast.makeText(mContext, | ||
+ | } | ||
+ | finally { | ||
+ | try { | ||
+ | output.close(); | ||
+ | fileWriter.close(); | ||
+ | } | ||
+ | catch (IOException e) { | ||
+ | Toast.makeText(mContext, | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | 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 110: | 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.1393856218.txt.gz · Last modified: 2014/03/03 14:16 by Denis Pallez