Skip to content
Snippets Groups Projects
Commit 924b4412 authored by Avi's avatar Avi
Browse files

Ajout des prototypes

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 663 additions and 0 deletions
FROM python:3.7
ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn
RUN set -e; \
apt-get update; \
apt-get install -y --no-install-recommends \
software-properties-common \
; \
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0xB1998361219BD9C9; \
apt-add-repository 'deb http://repos.azulsystems.com/debian stable main'; \
apt-get update; \
apt-get install -y --no-install-recommends \
zulu-11 \
; \
apt-get clean; \
rm -rf /var/lib/apt/lists/*
RUN set -e; \
pip install JPype1; \
pip install matplotlib
COPY . ./usr/src/app
WORKDIR /usr/src/app/src
CMD ["bash", "./myscript.sh"]
93.16978222
87.22838647
36.52150221
82.85924044
70.03544648
78.72792764
72.55339404
62.95355573
92.69623563
57.0489654
85.48418248
58.59918089
87.15900513
29.09755526
69.92444278
32.13234438
13.91679423
85.99668879
41.02583044
14.44662944
23.38689208
68.03427216
19.05721113
62.53131666
97.47234825
87.4420945
83.92964926
9.59805749
59.56345598
18.32706386
81.8869251
29.36690808
46.67683722
27.08309972
73.78917382
37.29819532
54.71809382
47.44060063
16.28681622
16.34230306
24.06389132
60.87726974
21.61384864
25.92906326
30.53646836
84.916816
2.49623802
49.19733722
4.77194984
17.34848237
75.91542483
34.27058755
25.35058104
83.45766374
44.56151359
65.45957673
90.31769677
83.64191836
24.11295434
40.55933331
92.09492492
2.15719554
73.25287555
58.62714525
76.14641901
12.08541374
15.38844599
19.25408221
62.62525918
47.423806
63.99584355
61.32385539
5.43916647
94.61169802
17.16244822
58.87525649
63.60357408
80.1126879
71.32595609
59.87079207
4.84298333
31.29610449
36.01371736
94.19988246
38.15702606
95.09470281
58.80774056
94.12372757
35.5821748
72.47327331
6.6944651888
5.80474576
9.355788537
13.08210395
8.71401834
7.571109755
21.85005663
83.6663767
8.2797237
56.98033245
\ No newline at end of file
123456789
\ No newline at end of file
package src;
import java.io.IOException;
public class Executor {
public static void main(String[] args) throws IOException {
for (int i = 1; i < 5; i++) {
String[] args2 = {args[0],"../tries/outputs_"+i+".txt"/*, args[1]*/};
PrototypeV1.main(args2);
}
}
}
\ No newline at end of file
package src;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Random;
public class PrototypeV1 {
public static ArrayList<Integer> getRandomArray(int nbNumber, int bound, long ... values){
ArrayList<Integer> myarray = new ArrayList<>();
int randomNumber;
Random objGenerator = new Random();
if(values.length==1){
objGenerator.setSeed(values[0]);
}
for (int iCount = 0; iCount < nbNumber; iCount++) {
randomNumber = objGenerator.nextInt(bound);
myarray.add(randomNumber);
}
return myarray;
}
//OTHER REFACTORING WAY
/*//Return an array of int based on the fixed number of iteration, bound
public static ArrayList<Integer> getRandomArray(int nbNumber, int bound, Random objGenerator) {
ArrayList<Integer> myarray = new ArrayList<>();
int randomNumber;
for (int iCount = 0; iCount < nbNumber; iCount++) {
randomNumber = objGenerator.nextInt(bound);
myarray.add(randomNumber);
}
return myarray;
}
//Return an array of int based on the fixed number of iteration, bound and passed seed
public static ArrayList<Integer> getRandomArrayFromASeed(int nbNumber, int bound, long seed) {
Random objGenerator = new Random();
objGenerator.setSeed(seed);
return getRandomArray(nbNumber, bound, objGenerator);
}*/
//Gather a long from a file passed in arguments
public static long gatherRootSeed(String myFile) throws FileNotFoundException {
File seedFile = new File(myFile);
Scanner myReader = new Scanner(seedFile);
String seed = myReader.nextLine();
long myseed = Long.valueOf(seed);
return myseed;
}
//Add one by one int and a line break to the file, from an array respectively passed in arguments
public static void addToFile(ArrayList<Integer> myarray, FileWriter output) throws IOException {
for (int i = 0; i < myarray.size(); i++) {
output.write(myarray.get(i).toString());
if (i < myarray.size() - 1) {
output.write(System.getProperty("line.separator"));
}
}
}
public static void main(String[] args) throws IOException {
File input = new File(args[0]);
FileWriter output = new FileWriter(args[1]);
Scanner myReader = new Scanner(input);
while (myReader.hasNextLine()) {
String data = myReader.nextLine();
float myFloat = Float.parseFloat(data);
output.write(Integer.toString((int) myFloat));
output.write(System.getProperty("line.separator"));
}
if(args.length<3) {
System.out.println("Without seed.");
//addToFile(getRandomArray(100, 100, new Random()), output);
addToFile(getRandomArray(100,100),output);
} else {
System.out.println("With seed.");
//addToFile(getRandomArrayFromASeed(100, 100,gatherRootSeed(args[2])), output);
addToFile(getRandomArray(100,100,gatherRootSeed(args[2])),output);
}
output.close();
System.out.println("Successfully wrote to the file.");
}
}
import matplotlib.pyplot as plt
import os
import numpy as np
cur_path = os.path.dirname(__file__)
new_path = os.path.relpath('../tries', cur_path) # path relatif du contenus de tries
entries = os.listdir(new_path) # nom de tous les fichiers
def createMainArray(nb_row):
mainArray = []
for i in range(nb_row):
mainArray.append([])
return mainArray
def createListOfAllArrays():
listOfLists = []
for i in entries:
fileObj = open(new_path + '/' + i, "r")
words = fileObj.read().splitlines()
fileObj.close()
treated = [int(x) for x in words]
listOfLists.append(treated)
numpyArray = np.array(listOfLists)
return numpyArray
def Main():
# Va contenir les tableau des 1ers elements, 2nd, 3eme, etc...
mainArray = createMainArray(200)
# Va contenir les tableaux d'entier des fichiers
numpyArray = createListOfAllArrays()
for j in range(numpyArray[0].size):
mainArray[j] = (numpyArray[:, j])
mainArray = np.array(mainArray)
print(mainArray)
plt.figure(figsize=(30,7))
boxesprops=dict(linewidth=0.1)
whiskersprops=dict(linewidth=0.1)
medianprops=dict(linewidth=0.1)
capprops=dict(linewidth=0.1)
flierprops=dict(linewidth=0.1)
for i in mainArray:
ax = plt.boxplot(mainArray.tolist(),
boxprops=boxesprops,
whiskerprops=whiskersprops,
medianprops=medianprops,
capprops=capprops,
flierprops=flierprops)
plt.savefig('/tmp/output/diag.png')
Main()
echo "Warning ! The diag.png file must be generated in tmp/src otherwise please edit this script according to your modification"
#sleep 2
echo "Compiling Prototypev3.java..."
javac Prototypev3.java
echo "Compilation done"
echo "Launching Executor.java with the inputs.txt file in arguments..."
java Executor.java ../inputs.txt
echo "Creation of outputs files in tries folder..."
echo "Treatement of outputs files by the python script ShowDatasV3.py..."
python ShowDatasV3.py
echo "Process Done!"
import java.util.Random;
public class DataProducer implements Runnable {
DataQueue dataQueue = Main.dataQueue;
@Override
public void run() {
Random random = new Random();
//random.setSeed(123456);
while (true) {
dataQueue.addFloat(Float.valueOf(random.nextFloat()*100));
}
}
}
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
public class DataQueue {
private int queueCapacity = 100;
private BlockingQueue<Float> queue = new ArrayBlockingQueue<>(queueCapacity);
public boolean addFloat(Float f){
return queue.offer(f);
}
public Float takeFloat(){
return queue.poll();
}
public Float getHead(){
return queue.peek();
}
public int getStock() {
return queue.size();
}
public int getQueueCapacity(){
return queueCapacity;
}
public boolean isFull() {
return queue.size() == queueCapacity;
}
}
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
public class Main {
public static DataQueue dataQueue = new DataQueue();
public static void main(String[] args) throws IOException {
DataProducer dataProducer = new DataProducer();
Thread threadDataProducer = new Thread(dataProducer);
ArrayList<Float> arrayListOfFloat = new ArrayList<>();
threadDataProducer.start();
FileWriter output = new FileWriter("outputFIFOFloat.txt");
int counter= 0;
while(dataQueue.getStock()>0 && counter<200) {
output.write(String.valueOf(Float.valueOf(dataQueue.getHead())));
if(counter<199){
output.write(System.getProperty("line.separator"));
}
arrayListOfFloat.add(dataQueue.takeFloat());
counter++;
}
System.out.println("Tableau Full");
output.close();
threadDataProducer.stop();
ArrayList<Integer> arrayListOfInt = new ArrayList<>();
for (int i = 0; i < arrayListOfFloat.size(); i++) {
arrayListOfInt.add(arrayListOfFloat.get(i).intValue());
}
for (int i = 0; i < arrayListOfInt.size(); i++) {
System.out.println(arrayListOfInt.get(i));
}
}
}
package versionBuffered_2LVL;
import java.io.IOException;
public class Arbiter implements Runnable {
Consommateur conso;
public Arbiter(Consommateur conso) {
this.conso = conso;
}
public void endExperience() throws IOException {
conso.finished();
System.out.println("Fin d'exp");
System.exit(0);
}
@Override
public void run() {
long start = System.currentTimeMillis();
long end = start + 2*1000;
while (start < end) {
start = System.currentTimeMillis();
}
try {
endExperience();
} catch (IOException e) {
e.printStackTrace();
}
}
}
package versionBuffered_2LVL;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
public class Buffer {
private int queueCapacity = 200;
private BlockingQueue<Float> queue = new ArrayBlockingQueue<>(queueCapacity);
public boolean addFloat(float f){
return queue.offer(f);
}
public float take() throws InterruptedException {
return queue.take();
}
public float getHead() {
return queue.peek();
}
public int getStock() {
return queue.size();
}
public int getQueueCapacity() {
return queueCapacity;
}
public boolean isFull() {
return queue.size() == queueCapacity;
}
}
package versionBuffered_2LVL;
import java.io.IOException;
public interface Consommateur {
void calculate(float f) throws IOException;
void finished() throws IOException;
}
package versionBuffered_2LVL;
import java.io.IOException;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
public class Main {
public static void main(String[] args) throws IOException, InterruptedException {
String outputFile = "src/versionBuffered_2LVL/outputsBuffered.txt";
BlockingQueue<Float> buffer = new ArrayBlockingQueue<>(200);
RealConso consommateur = new RealConso(outputFile);
Consommateur realConcurrentConso = new RealConcurrentConso(consommateur, buffer);
RealProd producteur = new RealProd(realConcurrentConso);
RealConcurrentProd realConcurrentProd = new RealConcurrentProd(buffer, consommateur);
consommateur.setRealConcurrentProd(realConcurrentProd);
Arbiter arbiter = new Arbiter(consommateur);
Thread Th_arbiter = new Thread(arbiter);
Thread Th_producteur = new Thread(producteur);
Thread Th_consommateur = new Thread(realConcurrentProd);
Th_producteur.start();
Th_consommateur.start();
Th_arbiter.start();
}
}
package versionBuffered_2LVL;
import java.util.concurrent.BlockingQueue;
public class RealConcurrentConso implements Consommateur {
RealConso conso;
BlockingQueue<Float> buffer;
public RealConcurrentConso(RealConso conso, BlockingQueue<Float> buffer){
this.conso = conso;
this.buffer = buffer;
}
@Override
public void calculate(float f){
buffer.offer(f);
System.out.println("RdC : J'ai ajouté "+f+" au buffer");
}
public void finished() {
System.out.println("RcC : J'ai terminé.");
}
}
package versionBuffered_2LVL;
import java.io.IOException;
import java.util.concurrent.BlockingQueue;
public class RealConcurrentProd implements Runnable{
BlockingQueue<Float> buffer;
Consommateur consommateur;
public RealConcurrentProd(BlockingQueue<Float> buffer, Consommateur consommateur){
this.buffer = buffer;
this.consommateur=consommateur;
}
public float takeFromBuffer() throws InterruptedException {
System.out.println("RdP : J'ai lu "+buffer.peek()+" et je l'ai donné au consommateur");
return buffer.take();
}
@Override
public void run() {
while(true){
try {
consommateur.calculate(takeFromBuffer());
} catch (InterruptedException | IOException e) {
e.printStackTrace();
}
}
}
}
package versionBuffered_2LVL;
import java.io.FileWriter;
import java.io.IOException;
public class RealConso implements Consommateur {
FileWriter output;
boolean firstLine = true;
public void setRealConcurrentProd(RealConcurrentProd realConcurrentProd) {
this.realConcurrentProd = realConcurrentProd;
}
RealConcurrentProd realConcurrentProd;
public RealConso(String f) throws IOException {
this.output = new FileWriter(f);
}
public int parseFloatToInt(float f) {
return ((int) f);
}
public void writeToFile(float f) throws IOException {
if (!firstLine) {
output.write(System.getProperty("line.separator"));
} else {
firstLine = false;
}
output.write(Integer.toString(parseFloatToInt(f)));
}
public void finished() throws IOException {
System.out.println("[Conso : J'ai terminé.");
output.close();
}
@Override
public void calculate(float f) throws IOException {
System.out.println("[Conso : J'écris "+(int) f+" dans le fichier.");
writeToFile(f);
}
}
package versionBuffered_2LVL;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Random;
public class RealProd implements Runnable {
Random random = new Random();
public void setFlag(Boolean flag) {
this.flag = flag;
}
boolean flag=true;
Consommateur concConso;
public RealProd(Consommateur concConso) throws FileNotFoundException {
this.concConso = concConso;
}
public float sendFloat() {
return random.nextFloat()*100;
}
@Override
public void run() {
while (true) {
float myFloat = sendFloat();
System.out.println("Prod : Je donne " + myFloat + " au RcC");
try {
concConso.calculate(myFloat);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
This diff is collapsed.
package versionBuffered_3LVL;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
public class Buffer {
private int queueCapacity = 20000;
private BlockingQueue<Float> queue = new ArrayBlockingQueue<>(queueCapacity);
public boolean addFloat(float f){
return queue.offer(f);
}
public float take() throws InterruptedException {
return queue.take();
}
public float getHead() {
return queue.peek();
}
public int getStock() {
return queue.size();
}
public int getQueueCapacity() {
return queueCapacity;
}
public boolean isFull() {
return queue.size() == queueCapacity;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment