diff --git a/src/.svn/entries b/src/.svn/entries
new file mode 100644
index 0000000000000000000000000000000000000000..a38a045d1debc3dfb1545cb73f90b323eb62a086
--- /dev/null
+++ b/src/.svn/entries
@@ -0,0 +1,28 @@
+10
+
+dir
+0
+http://trac.clermont.cemagref.fr/svn/PRIMA/AmiThreat1/src
+http://trac.clermont.cemagref.fr/svn/PRIMA
+add
+
+
+
+
+
+
+
+svn:special svn:externals svn:needs-lock
+
+
+
+
+
+
+
+
+
+
+
+6a2e9def-b413-4168-a192-dec410e7e464
+
diff --git a/src/Agent.java b/src/Agent.java
new file mode 100644
index 0000000000000000000000000000000000000000..cacc0a0d34b796d27e3fdd803ea80e5e67b91af8
--- /dev/null
+++ b/src/Agent.java
@@ -0,0 +1,383 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+/**
+ *
+ * @author Sylvie.huet
+ */
+public class Agent {
+
+    int nbAgentThisType;
+
+    double distAutruiInit;
+
+    int id = -1;
+
+    CulturalWorldView[] myCulture; //initialisées dans ordre lecture fichier : muslims, christians, areligious
+
+    CulturalWorldView[] myCultureInit;
+
+    int nbWorldView;
+
+    float alpha;
+
+    float[] opinionGlobalOnOthers;
+    double[] opinionOnOtherAgents;
+    double[] previousOpinionOnOtherAgents;
+
+    double opOfTheExtremistOnIt;
+
+    ResistingHostility pop;
+
+    String type; // agressor or victim for message agent 
+    String group; // areligious, muslims or christians
+    String openness; // inclusive or exclusive
+
+    float partInGroup; // part of this agent in the group (taux d'inclusif ou d'exclusif)
+
+    // Constructeur inutile pour permettre une initialisation provisoire
+    public Agent() {
+    }
+
+    public Agent(ResistingHostility me, int type, int id, String[] name, float[] adherence, float[] alow, float[] amax, int nbAgents, float alpha, int dimAdhesion, int nb) {
+        this.nbAgentThisType = nb;
+        this.id = id;
+        this.pop = me;
+        this.opinionGlobalOnOthers = new float[nbAgents];
+        this.distAutruiInit = 0.0;
+        opinionOnOtherAgents = new double[6];
+        previousOpinionOnOtherAgents = new double[6];
+        Arrays.fill(opinionOnOtherAgents, 0.0);
+        Arrays.fill(previousOpinionOnOtherAgents, 0.0);
+        if (type == 1) {
+            this.type = "inclusive";
+        } else {
+            this.type = "exclusive";
+        }
+        this.group = groupFromDimAdh(dimAdhesion);
+        Arrays.fill(opinionGlobalOnOthers, 0.0f);
+        this.nbWorldView = name.length;
+        this.alpha = alpha;
+        myCulture = new CulturalWorldView[nbWorldView];
+        myCultureInit = new CulturalWorldView[nbWorldView];
+        for (int i = 0; i < nbWorldView; i++) { // initialisées dans ordre lecture fichier : muslims, christians, areligious
+            myCulture[i] = new CulturalWorldView(name[i], adherence[i], alow[i], amax[i]);
+            myCultureInit[i] = new CulturalWorldView(name[i], adherence[i], alow[i], amax[i]);
+        }
+    }
+
+    // This is the agent constructor for the source
+    public Agent(ResistingHostility me, String type, float[] adherence, float[] alow, float[] amax, float alpha, int dimAdhesion, int nb) {
+        this.nbAgentThisType = nb;
+        this.distAutruiInit = 0.0;
+        this.type = type;
+        this.pop = me;
+        this.group = groupFromDimAdh(dimAdhesion);
+        this.nbWorldView = adherence.length;
+        this.alpha = alpha;
+        myCulture = new CulturalWorldView[nbWorldView];
+        myCultureInit = new CulturalWorldView[nbWorldView];
+        for (int i = 0; i < nbWorldView; i++) {
+            myCulture[i] = new CulturalWorldView(type, adherence[i], alow[i], amax[i]);
+            myCultureInit[i] = new CulturalWorldView(type, adherence[i], alow[i], amax[i]);
+        }
+    }
+
+    // This is the agent for generating relevant CWW
+    public Agent(String openness, float[] adherence, float[] alow, float[] amax, float alpha, int nb) {
+        this.nbAgentThisType = nb;
+        this.distAutruiInit = 0.0;
+        this.type = type;
+        this.openness = openness;
+        //this.pop = me;
+        this.nbWorldView = adherence.length;
+        this.alpha = alpha;
+        myCulture = new CulturalWorldView[nbWorldView];
+        for (int i = 0; i < nbWorldView; i++) {
+            myCulture[i] = new CulturalWorldView(type, adherence[i], alow[i], amax[i]);
+        }
+    }
+
+    public Agent(String group, String openness, float representativity, float[] adherence, float[] alow, float[] amax, float alpha, int nb) {
+        this.nbAgentThisType = nb;
+        this.distAutruiInit = 0.0;
+        this.group = group;
+        this.openness = openness;
+        this.partInGroup = representativity;
+        this.nbWorldView = adherence.length;
+        this.alpha = alpha;
+        myCulture = new CulturalWorldView[nbWorldView];
+        for (int i = 0; i < nbWorldView; i++) {
+            myCulture[i] = new CulturalWorldView(type, adherence[i], alow[i], amax[i]);
+        }
+    }
+
+    // This is the agent for generating relevant CWW
+    public Agent(Agent A) {
+        this.nbAgentThisType = A.nbAgentThisType;
+        this.distAutruiInit = A.distAutruiInit;
+        this.group = A.group;
+        this.openness = A.openness;
+        this.partInGroup = A.partInGroup;
+        //this.pop = me;
+        this.nbWorldView = A.nbWorldView;
+        this.alpha = A.alpha;
+        myCulture = new CulturalWorldView[nbWorldView];
+        float[] adherence = new float[nbWorldView];
+        float[] alow = new float[nbWorldView];
+        float[] amax = new float[nbWorldView];
+        for (int i = 0; i < nbWorldView; i++) {
+            adherence[i] = A.myCulture[i].maPosition;
+            alow[i] = A.myCulture[i].alow;
+            amax[i] = A.myCulture[i].amax;
+        }
+        for (int i = 0; i < nbWorldView; i++) {
+            myCulture[i] = new CulturalWorldView(type, adherence[i], alow[i], amax[i]);
+        }
+    }
+
+    public double computeOpinionOnOtherMAPosition(float ad, CulturalWorldView c) {
+        double w = 0.0f; // opinion about another agent's maPosition at the cultural worldview k
+        double temp = 0;
+        if (ad == c.maPosition) {
+            ad = ad + 0.000001f;
+        }
+        try {
+            if ((ad < c.amax) && (ad > c.alow)) {
+                w = 1.0;
+            } else if (ad <= c.alow) {
+                temp = Math.exp(1 + ((ad - c.maPosition) / (c.maPosition - c.alow)));
+                w = (float) ((temp - 1) / (temp + 1));
+            } else if (ad >= c.amax) {
+                temp = Math.exp(1 + ((c.maPosition - ad) / (c.amax - c.maPosition)));
+                w = (float) ((temp - 1) / (temp + 1));
+            }
+            if (Double.isNaN(w)) {
+                throw new Exception(" w is not a number " + c.alow + " " + c.maPosition + " " + c.amax + " ad " + ad + " w = " + w);
+            }
+
+        } catch (Exception error) {
+            error.printStackTrace();
+        }
+        return w;
+    }
+
+    public double computeOpinionOnOtherMAPosition(float ad, CulturalWorldView c, boolean show) {
+        double w = 0.0f; // opinion about another agent's maPosition at the cultural worldview k
+        double temp = 0;
+        if (ad == c.maPosition) {
+            ad = ad + 0.000001f;
+        }
+        try {
+            if ((ad < c.amax) && (ad > c.alow)) {
+                w = 1.0;
+            } else if (ad <= c.alow) {
+                temp = Math.exp(1 + ((ad - c.maPosition) / (c.maPosition - c.alow)));
+                w = (float) ((temp - 1) / (temp + 1));
+            } else if (ad >= c.amax) {
+                temp = Math.exp(1 + ((c.maPosition - ad) / (c.amax - c.maPosition)));
+                w = (float) ((temp - 1) / (temp + 1));
+            }
+            if (Double.isNaN(w)) {
+                throw new Exception(" w is not a number " + c.alow + " " + c.maPosition + " " + c.amax + " ad " + ad + " w = " + w);
+            }
+            if (show) {
+                System.err.print(" dot " + ad + " jugeur " + c.alow + " " + c.maPosition + " " + c.amax + " w = " + w + " ");
+            }
+        } catch (Exception error) {
+            error.printStackTrace();
+        }
+        return w;
+    }
+
+    public double opinionOnOthers(Agent A) {
+        double opTot = 0.0f;
+        double opIJ = 0.0f;
+        for (int i = 0; i < nbWorldView; i++) {
+            opIJ = opinionAboutOtherAgentForOneCWW(myCulture[i], A.myCulture[i], pop.nbPoints);
+            opTot = opTot + opIJ;
+        }
+        return opTot / (float) nbWorldView;
+    }
+
+    public double opinionOnOthers(Agent A, int nbPoints) {
+        double opTot = 0.0f;
+        double opIJ = 0.0f;
+        for (int i = 0; i < nbWorldView; i++) {
+            opIJ = opinionAboutOtherAgentForOneCWW(myCulture[i], A.myCulture[i], nbPoints);
+            opTot = opTot + opIJ;
+        }
+        return opTot / (float) nbWorldView;
+    }
+
+    public double opinionOnOthers(Agent A, boolean notfromInitState) {
+        // I have changed but I don't know the other has changed
+        double opTot = 0.0f;
+        double opIJ = 0.0f;
+        for (int i = 0; i < nbWorldView; i++) {
+            if (notfromInitState) {
+                opIJ = opinionAboutOtherAgentForOneCWW(myCulture[i], A.myCulture[i], pop.nbPoints);
+            } else if ((A.group.equalsIgnoreCase(this.group)) && (A.type.equalsIgnoreCase(this.type))) {
+                opIJ = opinionAboutOtherAgentForOneCWW(myCulture[i], myCulture[i], pop.nbPoints);
+            } else {
+                opIJ = opinionAboutOtherAgentForOneCWW(myCulture[i], A.myCultureInit[i], pop.nbPoints);
+            }
+            opTot = opTot + opIJ;
+        }
+        return opTot / (double) nbWorldView;
+    }
+
+    public double opinionAboutOtherAgentForOneCWW(CulturalWorldView cI, CulturalWorldView cJ, int nbPoints) { // an agent's J cultural worldview
+        double opI = 0.0f;
+        double temp = 0.0f;
+        float[] op = sampleTolSegmentFromGrid(nbPoints, cJ);
+        for (int i = 0; i < op.length; i++) {
+            opI = computeOpinionOnOtherMAPosition(op[i], cI);
+            temp = temp + opI;
+        }
+        temp = temp / (double) op.length;
+        return temp;
+    }
+
+    public double opinionAboutOtherAgentForOneCWW(CulturalWorldView cI, CulturalWorldView cJ, int nbPoints, boolean show) { // an agent's J cultural worldview
+        double opI = 0.0f;
+        double temp = 0.0f;
+        float[] op = sampleTolSegmentFromGrid(nbPoints, cJ);
+        for (int i = 0; i < op.length; i++) {
+            opI = Agent.this.computeOpinionOnOtherMAPosition(op[i], cI, show);
+            temp = temp + opI;
+        }
+        temp = temp / (double) op.length;
+        return temp;
+    }
+
+    public float[] sampleTolSegmentBugged(int nbPoints, CulturalWorldView cJ) {
+        float[] s = new float[nbPoints];
+        // we sample starting from the maPosition of the sampling segment and picked out the same number of point on the left and on the right
+        int countP = 0;
+        if (nbPoints % 2 == 1) { // nb Points est impair
+            // a first sampled point at the maPosition value
+            s[countP] = 1.0f; // by construction
+            countP++;
+            nbPoints = nbPoints - 1;
+        }
+        nbPoints = nbPoints / 2;
+        // sampling on the right side
+        float dist = cJ.amax - cJ.maPosition;
+        float interv = dist / (float) (nbPoints);
+        float depart = cJ.maPosition + (0.5f * interv);
+        for (int i = 0; i < nbPoints; i++) {
+            s[countP] = depart + (float) i * interv;
+            countP++;
+        }
+        // sampling on the left side
+        dist = cJ.maPosition - cJ.alow;
+        interv = dist / (float) (nbPoints);
+        depart = cJ.alow + (0.5f * interv);
+        for (int i = 0; i < nbPoints; i++) {
+            s[countP] = depart + (float) i * interv;
+            countP++;
+        }
+        return s;
+    }
+
+    public float[] sampleTolSegment(int nbPoints, CulturalWorldView cJ) {
+        float dist = cJ.amax - cJ.alow;
+        float interv = dist / (float) (nbPoints);
+        float depart = cJ.alow + (0.5f * interv);
+        float[] s = new float[nbPoints];
+        for (int i = 0; i < nbPoints; i++) {
+            s[i] = depart + (float) i * interv;
+        }
+        return s;
+    }
+
+    public float[] sampleTolSegmentFromGrid(int nbPoints, CulturalWorldView cJ) { // allow to approximate the segment using always the same dots for everyone
+        float interv = 2.0f / (float) (nbPoints); // this is constant 
+        float depart = -1.0f;
+        float gridDot = -1.0f;
+        float reserv = -1.0f;
+        for (int i = 0; i <= nbPoints; i++) {
+            gridDot = depart + (float) i * interv;
+            if (gridDot > cJ.alow) { // we take the closer in the segment
+                depart = gridDot;
+                reserv = gridDot - interv;
+                i = nbPoints + 1;
+            }
+        }
+        ArrayList<Float> points = new ArrayList<Float>();
+        float gridPoint = 0.0f;
+        for (int i = 0; i <= nbPoints; i++) {
+            gridPoint = depart + (float) i * interv;
+            if (gridPoint <= cJ.amax) {
+                points.add(gridPoint);
+            } else {
+                i = nbPoints + 1;
+            }
+        }
+        float[] s;
+        if (points.size() > 0) {
+            s = new float[points.size()];
+            for (int i = 0; i < points.size(); i++) {
+                s[i] = points.get(i).floatValue();
+            }
+        } else {
+            s = new float[1];
+            s[0] = reserv;
+        }
+        return s;
+    }
+
+    public void reactionToMessage(int type, Agent emetteur) {
+        reactionToThreatMessageOneDim(emetteur);
+    }
+
+    public void reactionToThreatMessageOneDim(Agent emetteur) {
+        // I (this) compute what the "emetteur" think of me 
+        opOfTheExtremistOnIt = emetteur.opinionOnOthers(this);
+        int dimToChange = emetteur.mainDimension();
+        if (opOfTheExtremistOnIt < 0.0f) {
+            float mu = alpha * (float) ((Math.exp(opOfTheExtremistOnIt) - 1) / (Math.exp(opOfTheExtremistOnIt) + 1));
+            myCulture[dimToChange].changeBoundIfThreat(mu, emetteur.myCulture[dimToChange].maPosition, pop.epsilon);
+        }
+    }
+
+    public int mainDimension() {
+        int dim = 0;
+        float adherMax = Float.MIN_VALUE;
+        for (int i = 0; i < myCulture.length; i++) {
+            if (myCulture[i].maPosition > adherMax) {
+                adherMax = myCulture[i].maPosition;
+                dim = i;
+            }
+        }
+        return dim;
+    }
+
+    public int mainCWWFromGroup() {
+        int cww = 0; // muslims
+        if (this.group.equals(new String("areligious"))) {
+            cww = 2;
+        } else if (this.group.equals(new String("christians"))) {
+            cww = 1;
+        }
+        return cww;
+    }
+
+    //
+    public String groupFromDimAdh(int dimAdhesion) {
+        String g = new String("muslims");
+        if (dimAdhesion == 2) {
+            g = new String("areligious");
+        } else if (dimAdhesion == 1) {
+            g = new String("christians");
+        }
+        return g;
+    }
+}
diff --git a/src/CulturalWorldView.java b/src/CulturalWorldView.java
new file mode 100644
index 0000000000000000000000000000000000000000..c8d66782e6efe8a53850fb2117de63f08446e252
--- /dev/null
+++ b/src/CulturalWorldView.java
@@ -0,0 +1,59 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/**
+ *
+ * @author Sylvie.huet
+ */
+public class CulturalWorldView {
+
+    //We consider a population of N agents, each agent i has an identity first defined by 3 values 
+    // between -1 and +1, corresponding to its maPosition or rejection of a cultural world view. 
+    // Agent's cultural worldviews: A positive value expresses maPosition while a negative one expresses rejection. 
+    // The absolute value expresses the intensity of the maPosition of rejection. 
+    // Tolerance: the agent is also defined by tolerance limits above and below this maPosition or rejection values. 
+    float maPosition;
+    float alow;
+    float amax;
+    float exAmax ;
+    String name;
+
+    public CulturalWorldView(String name, float adherence, float alow, float amax) {
+        this.name = name;
+        this.maPosition = adherence;
+        this.alow = alow;
+        this.amax = amax;
+        if (Math.abs(adherence - amax) < 0.0000001f) { this.amax = adherence+0.00001f ; } // pour résoudre problème d'encodage de m.... 
+        if (Math.abs(adherence - alow) < 0.0000001f) { this.alow = adherence-0.00001f ; }
+    }
+
+    public void changeBoundIfThreat(float mu, float adherenceSource, float epsilon) {
+        exAmax = amax ;
+        float base = 0.0f;
+        float dist1 = Math.abs(adherenceSource - alow);
+        float dist2 = Math.abs(adherenceSource - amax);
+        float newBound = 0.0f;
+        if (dist1 < dist2) {
+            base = alow;
+        } else {
+            base = amax;
+        }
+        if (dist1 == dist2) {
+            if (Math.random() < 0.5) {
+                base = alow;
+            } else {
+                base = amax;
+            }
+        }
+        newBound = base + mu * (base - maPosition - epsilon * (Math.abs(base - maPosition) / (base - maPosition)));
+        if (base == alow) {
+            alow = newBound;
+        } else {
+            amax = newBound;
+        }
+    }
+
+}
diff --git a/src/DoubleCollectionIterator.java b/src/DoubleCollectionIterator.java
new file mode 100644
index 0000000000000000000000000000000000000000..89fb18aa958edbe9c81f14422361a416419286f7
--- /dev/null
+++ b/src/DoubleCollectionIterator.java
@@ -0,0 +1,91 @@
+/*
+ *  Copyright (C) 2010 Cemagref
+ * 
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ * 
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ * 
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+
+import java.util.List;
+
+/**
+ * Utility classes for iterating on an array of Double, double, Float or float
+ * for retrieving a double value.
+ * 
+ * @author Nicolas Dumoulin <nicolas.dumoulin@cemagref.fr>
+ */
+public interface DoubleCollectionIterator<T> {
+
+    public double get(T array, int index);
+
+    public int size(T array);
+    public final static DoubleCollectionIterator<List<Double>> fromDoubleClassList = new DoubleCollectionIterator<List<Double>>() {
+
+        @Override
+        public double get(List<Double> array, int index) {
+            return array.get(index);
+        }
+
+        @Override
+        public int size(List<Double> array) {
+            return array.size();
+        }
+    };
+
+    abstract static class DoubleArrayIterator<T> implements DoubleCollectionIterator<T> {
+
+        @Override
+        public int size(T array) {
+            return ((Object[]) array).length;
+        }
+    }
+    public final static DoubleCollectionIterator<Double[]> fromDoubleClass = new DoubleArrayIterator<Double[]>() {
+
+        @Override
+        public double get(Double[] array, int index) {
+            return array[index];
+        }
+    };
+    public final static DoubleCollectionIterator<double[]> fromDoublePrimitive = new DoubleArrayIterator<double[]>() {
+
+        @Override
+        public double get(double[] array, int index) {
+            return array[index];
+        }
+
+        @Override
+        public int size(double[] array) {
+            return array.length;
+        }
+    };
+    public final static DoubleCollectionIterator<Float[]> fromFloatClass = new DoubleArrayIterator<Float[]>() {
+
+        @Override
+        public double get(Float[] array, int index) {
+            return array[index];
+        }
+    };
+    public final static DoubleCollectionIterator<float[]> fromFloatPrimitive = new DoubleArrayIterator<float[]>() {
+
+        @Override
+        public double get(float[] array, int index) {
+            return array[index];
+        }
+
+        @Override
+        public int size(float[] array) {
+            return array.length;
+        }
+    };
+}
diff --git a/src/Message.java b/src/Message.java
new file mode 100644
index 0000000000000000000000000000000000000000..0d00f0f482621682cfd557d4885f6415aac3cdba
--- /dev/null
+++ b/src/Message.java
@@ -0,0 +1,29 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+
+
+/**
+ *
+ * @author sylvie.huet
+ */
+public class Message {
+    
+    int time ; // iteration at which the message is delivered
+    
+    int type ; // 1 = threat ; 2 = compassion
+    
+    Agent emetteur ; // id of the agent threatening the other agent or being a victim (possibly benefiting from compassion
+
+    public Message(int time, int type, Agent emetteur) {
+        this.time = time ;
+        this.type = type;
+        this.emetteur = emetteur;
+    }
+    
+    
+    
+}
diff --git a/src/ProcessingException.java b/src/ProcessingException.java
new file mode 100644
index 0000000000000000000000000000000000000000..dc4afa3c4dc256d7e0f042b0945013a854f01760
--- /dev/null
+++ b/src/ProcessingException.java
@@ -0,0 +1,41 @@
+/*
+ *  Copyright (C) 2010 Cemagref
+ * 
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ * 
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ * 
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+
+/**
+ * Exception that can be thrown while processing an event and
+ * encountering some errors.
+ *
+ * @author Nicolas Dumoulin <nicolas.dumoulin@cemagref.fr>
+ */
+public class ProcessingException extends Exception {
+
+    public ProcessingException(Throwable cause) {
+        super(cause);
+    }
+
+    public ProcessingException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public ProcessingException(String message) {
+        super(message);
+    }
+
+    
+}
diff --git a/src/Random.java b/src/Random.java
new file mode 100644
index 0000000000000000000000000000000000000000..1874afa5543a69b638abe1d908db548c52c9e76f
--- /dev/null
+++ b/src/Random.java
@@ -0,0 +1,249 @@
+/*
+ *  Copyright (C) 2010 Cemagref
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.SortedMap;
+import umontreal.iro.lecuyer.probdist.ExponentialDistFromMean;
+import umontreal.iro.lecuyer.randvar.ExponentialGen;
+import umontreal.iro.lecuyer.randvar.NormalGen;
+import umontreal.iro.lecuyer.randvar.RandomVariateGen;
+import umontreal.iro.lecuyer.rng.MRG32k3a;
+import umontreal.iro.lecuyer.rng.RandomPermutation;
+
+/**
+ * @author Nicolas Dumoulin <nicolas.dumoulin@cemagref.fr>
+ * @author sylvie.huet
+ */
+public class Random {
+
+    private MRG32k3a randomStream;
+
+    /**
+     * This method returns an integer picked out following a Uniform law between i and i1. The values i and i1 are included (can be picked out)
+     */
+    public int nextInt(int i, int i1) {
+        return randomStream.nextInt(i, i1);
+    }
+
+    /**
+     * This method returns a double picked out following a Uniform law between 0 and 1 with 0 and 1 excluded (can't be picked out)
+     */
+    public double nextDouble() {
+        return randomStream.nextDouble();
+    }
+
+    public int nextIndexWithDistribution(float[] distribution) {
+        return nextIndexWithDistribution(distribution, DoubleCollectionIterator.fromFloatPrimitive);
+    }
+
+    public int nextIndexWithDistribution(Double[] distribution) {
+        return nextIndexWithDistribution(distribution, DoubleCollectionIterator.fromDoubleClass);
+    }
+
+    public int nextIndexWithDistribution(List<Double> distribution) {
+        return nextIndexWithDistribution(distribution, DoubleCollectionIterator.fromDoubleClassList);
+    }
+
+    /**
+     * Picks out randomly an object in the given list.
+     * @param <T>
+     * @param objects
+     * @return 
+     */
+    public <T> T nextObject(List<T> objects) {
+        return nextObject(objects, false);
+    }
+
+    /**
+     * Picks out randomly an object in the given list.
+     * @param <T>
+     * @param objects
+     * @param remove if true, the returned object is removed from the list
+     * @return null if the list is null or empty.
+     */
+    public <T> T nextObject(List<T> objects, boolean remove) {
+        if (objects == null || objects.isEmpty()) {
+            return null;
+        }
+        if (remove) {
+            return objects.remove(nextInt(0, objects.size() - 1));
+        } else {
+            return objects.get(nextInt(0, objects.size() - 1));
+        }
+    }
+
+    /**
+     * Pick out an object in the values of a map, according to the probilities stored in the keys
+     */
+    public <T> T nextMapObjectWithDistributionInKeys(SortedMap<Double, T> map) {
+        double rando = nextDouble();
+        double value = map.firstKey();
+        Iterator<Double> keysIterator = map.keySet().iterator();
+        double sum = keysIterator.next();
+        while (keysIterator.hasNext()) {
+            sum += value;
+            if (sum >= rando) {
+                break;
+            }
+            value = keysIterator.next();
+        }
+        return map.get(value);
+    }
+
+    public int nextIndexWithDistribution(double[] distribution) {
+        return nextIndexWithDistribution(distribution, DoubleCollectionIterator.fromDoublePrimitive);
+    }
+
+    /**
+     * Pick an index in an array covered by a distribution (non-cumulative). If the sum
+     * of probabilities is less than 1, it may occur that the random index is out of the
+     * given probabilities. In this case, the last index is returned.
+     * 
+     * @param distribution
+     * @return the selected index or -1 if out of distribution.
+     */
+    public <T> int nextIndexWithDistribution(T distribution, DoubleCollectionIterator<T> iterator) {
+        double rando = nextDouble();
+        int index = 0;
+        double sum = iterator.get(distribution, index);
+        while (rando > sum) {
+            index++;
+            if (index == iterator.size(distribution)) {
+                break;
+            }
+            sum += iterator.get(distribution, index);
+        }
+        if (index == iterator.size(distribution)) {
+            // return the last index
+            index--;
+        }
+
+        return index;
+    }
+
+    /**
+     * Use this method to initialize a generator based on a statistical distribution.
+     * For example, this code create a generator from a normal distribution:
+     * <p><code>NormalGen normalGenerator = new NormalACRGen(null, 0, 1);<br/>
+     * Random.setRandomStreamInDist(normalGenerator);
+     * </code></p>
+     * @param rvg The distribution-based generator to initialize
+     */
+    public void setRandomStreamInDist(RandomVariateGen rvg) {
+        rvg.setStream(randomStream);
+    }
+
+    /**
+     * This method return a random order for a sequence of
+     * leng numbers.
+     */
+    public int[] randomList(int leng) {
+        int[] vec = new int[leng];
+        for (int i = 0; i < leng; i++) {
+            vec[i] = i;
+        }
+        RandomPermutation.shuffle(vec, randomStream);
+        return vec;
+    }
+
+    public String getSeedToString() {
+        StringBuilder buff = new StringBuilder();
+        for (long val : randomStream.getState()) {
+            buff.append(val);
+            buff.append("   ");
+        }
+        return buff.toString();
+        // this code make troubles in exception stacktrace formatting (don't know why…)
+        //return Arrays.toString(randomStream.getState());
+    }
+
+    /**
+     * This method should only be called by the simulation starter.
+     * The initial status for the RNG is initialized by the simulator at startup.
+     * @param seed
+     */
+    public void setSeed(long[] seed) throws ProcessingException {
+        if (randomStream != null) {
+            throw new ProcessingException("Trying to reinit the seed of the RNG although it is already initialized!");
+        }
+        randomStream = new MRG32k3a();
+        randomStream.setSeed(seed);
+    }
+
+    public ExponentialGen createExponentialGenFromMean(float mean) {
+        return new ExponentialGen(randomStream, new ExponentialDistFromMean(mean));
+    }
+
+    /**
+     * Pick out a float following a Normal law
+     */
+    public float pickOutNormalLaw(float m, float std) {
+        return (float) NormalGen.nextDouble(randomStream, m, std);
+    }
+
+    public double pickOutNormalLaw(double m, double std) {
+        return NormalGen.nextDouble(randomStream, m, std);
+    }
+
+    /**
+     * Randomly permutes list. This method permutes the whole list.
+     * @param list the list to process
+     */
+    public void shuffle(List list) {
+        RandomPermutation.shuffle(list, randomStream);
+    }
+
+    /**
+     * Picks randomly some elements from a list.
+     * @param <E>
+     * @param list
+     * @param nb the number of elements to pick out
+     * @return null, if nb <= 0
+     */
+    public <E> List<E> pickElements(List<E> list, int nb) {
+        if (nb <= 0) {
+            return null;
+        }
+        List<E> result = new ArrayList<E>(nb);
+        List<E> copy = new ArrayList<E>(list);
+        for (int i = 0; i < nb; i++) {
+            int index = nextInt(0, copy.size() - 1);
+            result.add(copy.remove(index));
+        }
+        return result;
+    }
+
+    /**
+     * Build an array of indexes for randomly picking elements in a matrix.
+     * @param elements
+     * @return an array of two-dimensional indexes
+     */
+    public List<int[]> buildRandomMatrixIndexes(Object[][] elements) {
+        List<int[]> indexes = new ArrayList<int[]>();
+        for (int i = 0; i < elements.length; i++) {
+            for (int j = 0; j < elements[i].length; j++) {
+                indexes.add(new int[]{i, j});
+            }
+        }
+        shuffle(indexes);
+        return indexes;
+    }
+}
diff --git a/src/ResistingHostility.java b/src/ResistingHostility.java
new file mode 100644
index 0000000000000000000000000000000000000000..ce2d3820e1d6253aa87bbb7088288fb9d83865b4
--- /dev/null
+++ b/src/ResistingHostility.java
@@ -0,0 +1,823 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ *
+ * @author Sylvie.huet
+ */
+public class ResistingHostility {
+
+    /**
+     * @param args the command line arguments
+     */
+    List<Message> messages;
+    Agent[] population;
+    static int nbWorldView;
+    int nbPoints; // nbPoints to sample in j's tolerance segment to define the opinions of i about j 
+    int nbIter;
+    float epsilon; // min possible tolerance
+    float alpha; // Parametre
+    int inclusifs;
+    int exclusifs;
+    int nbMessages;
+    float partExclusive;
+    static Random myRand;
+    int iteration;
+    static Tools myPop; // reader of the entering files
+    static float[] parametres;
+
+    public int getIteration() {
+        return iteration;
+    }
+    int source; // for the message
+    String messageFile;
+    String nomExpe;
+    static String popFile;
+    static boolean expeFini;
+    static float randomized; // this is to change slightly and randomly the entering cultural worldviews pattern of agents
+    static int sizePop;
+
+    public static void main(String[] args) {
+        // parameters by default
+        int outputType = 0; // meaning the output is average values of attitudes over the population (1 means details for each agent type)
+        popFile = new String("expDesign.xls");
+        String nameFileResults = new String("globalResultsAVG.csv");
+        sizePop = 1000;
+        int nbRepliques = 1; // 1 suffit dans le cas ou pop init pas random car pas d'heuristique de rencontre
+        float alpha = 0.5f;
+        float epsilon = 0.000001f;
+        int nbPoint = 400;
+        nbWorldView = 3;
+        randomized = 0.0f; // allow to vary slightly the agents (if equal to 0, the agents are only defined by the initialisation from the file)
+        // parameters of the user if they are given 
+        if (args.length > 0) {
+            outputType = new Integer(args[0]).intValue();
+            nameFileResults = args[1];
+            popFile = args[2];
+            sizePop = new Integer(args[3]).intValue();;
+            nbRepliques = new Integer(args[4]).intValue();; // 1 suffit dans le cas ou pop init pas random car pas d'heuristique de rencontre
+            alpha = new Float(args[5]).floatValue();
+            epsilon = new Float(args[6]).floatValue();
+            nbPoint = new Integer(args[7]).intValue();;
+            nbWorldView = new Integer(args[8]).intValue();;
+            randomized = new Float(args[9]).floatValue(); // allow to vary slightly the agents (if equal to 0, the agents are only defined by the initialisation from the file)
+        }
+
+        parametres = new float[6];
+        parametres[1] = randomized;
+        parametres[2] = alpha;
+        parametres[3] = epsilon;
+        parametres[4] = (float) (nbPoint);
+        parametres[5] = (float) (nbWorldView);
+        boolean knowTheOthersHaveChanged = true; // to compute the opinions of the population of the group of each agent making them taking into account others have changed or not
+        myPop = new Tools();
+        if (outputType == 0) { // the user wishes to have the average values of opinion over the population
+            myPop.ecritureInFileSourceStudyFromDataAVGSTD(nameFileResults);
+        } else { // it is equal to 1 and the user asks for the detailed value for each type of agents
+            myPop.ecritureInFileSourceStudyFromDataDetails(nameFileResults);
+        }
+        try {
+            myRand = new Random();
+            long stuf = (long) (12345 * Math.random());
+            myRand.setSeed(new long[]{stuf, 12345, 12345, 12345, 12345, 12345});
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        int end = 0;
+        int i = 1; //
+        float numExpe = 0.0f;
+        expeFini = false;
+        while (!expeFini) {
+            numExpe++;
+            for (int j = 0; j < nbRepliques; j++) {
+                parametres[0] = (float) (j); // numReplique
+                end = i + (nbWorldView * 2) - 1;
+                System.err.println("I read and try to launch (if they exist in the file) the experimentations number " + i + " to " + end + " and the replica number " + j);
+                new ResistingHostility(alpha, epsilon, nbPoint, i, end, knowTheOthersHaveChanged, outputType);
+            }
+            i = end + 1;
+        }
+        System.err.println("The experimental design is finished. The last experimentations do not exist in the file.");
+        myPop.writResult.close();
+        myPop = null;
+    }
+
+    int[] typeId;
+
+    public ResistingHostility(float alpha, float epsilon, int nbPoint, int firstLine, int endLine, boolean knowTheOthersHaveChanged, int outputType) {
+        this.alpha = alpha;
+        this.epsilon = epsilon;
+        this.nbPoints = nbPoint; // nbPoints to sample in j's tolerance segment to define the opinions of i about j 
+        expeFini = initAgentsFromFile(firstLine, endLine, knowTheOthersHaveChanged);
+        if (!expeFini) {
+            typeId = new int[6];
+            Arrays.fill(typeId, -1);
+            typeId[0] = 0;
+            String lastType = population[0].type;
+            String group = population[0].group;
+            int count = 1;
+            for (int i = 1; i < sizePop; i++) {
+                if (!population[i].type.equalsIgnoreCase(lastType) || !population[i].group.equalsIgnoreCase(group)) {
+                    typeId[count] = i;
+                    count++;
+                    lastType = population[i].type;
+                    group = population[i].group;
+                }
+            }
+            for (int z = 0; z < typeId.length; z++) {
+                for (int a = 0; a < typeId.length; a++) {
+                    population[typeId[z]].previousOpinionOnOtherAgents[a] = population[typeId[z]].opinionOnOthers(population[typeId[a]], knowTheOthersHaveChanged);
+                }
+            }
+            messageFile = myPop.messageFileName;
+            nomExpe = myPop.country;
+            initMessage();
+            this.nbIter = nbMessages;
+            computeAgentsOpinions();
+            if (outputType == 0) { // the user wishes to have the average values of opinion over the population
+                iteration(knowTheOthersHaveChanged);
+            } else { // it is equal to 1 and the user asks for the detailed value for each type of agents
+                iterationWithAgentDetail(knowTheOthersHaveChanged);
+            }
+        }
+    }
+
+    public boolean initAgentsFromFile(int firstLine, int endLine, boolean knowsAboutOthers) {
+        myPop.go = true;
+        boolean fini = countPop(firstLine, endLine);
+        if (!fini) {
+            population = new Agent[sizePop];
+            String[] name = new String[nbWorldView];
+            name[0] = new String("muslims");
+            name[1] = new String("christians");
+            name[2] = new String("areligious");
+            int count = 0;
+            int z = 0;
+            while (myPop.go) {
+                z = 0;
+                float[][] popToGenere = myPop.lireExpDesignInitPop(firstLine, endLine, popFile, nbWorldView);
+                sizePop = (int) popToGenere[0][12];
+                population = new Agent[sizePop];
+                for (int i = 0; i < popToGenere.length; i++) { // i represents each type of agents
+                    int dimAdhes = (int) popToGenere[i][0];
+                    int nb = (int) (popToGenere[i][1]); // 
+                    int type = (int) popToGenere[i][2];
+                    maPosition = new float[nbWorldView];
+                    lowTol = new float[nbWorldView];
+                    highTol = new float[nbWorldView];
+                    Arrays.fill(maPosition, 0.0f);
+                    Arrays.fill(lowTol, 0.0f);
+                    Arrays.fill(highTol, 0.0f);
+                    z = 0;
+                    for (int v = 0; v < nbWorldView;) {
+                        lowTol[v] = popToGenere[i][3 + v + z];
+                        maPosition[v] = popToGenere[i][4 + v + z];
+                        highTol[v] = popToGenere[i][5 + v + z];
+                        v = v + 1;
+                        z = z + 2;
+                    }
+
+                    int j = 0;
+                    for (j = 0; j < nb; j++) {
+                        initAgentRandomized();
+                        population[count] = new Agent(this, type, count, name, maPosition, lowTol, highTol, sizePop, alpha, dimAdhes, nb);
+                        count++;
+                    }
+
+                }
+
+                firstLine = firstLine + popToGenere.length;
+                if (firstLine > endLine) {
+                    myPop.go = false;
+                }
+            }
+        }
+        return fini;
+    }
+
+    public boolean countPop(int fLine, int endL) {
+        Tools myPop = new Tools();
+        int firstLine = fLine;
+        int count = 0;
+        int countInclusif = 0;
+        int countExclusif = 0;
+        while (myPop.go) {
+            float[][] popToGenere = myPop.lireExpDesignInitPop(firstLine, endL, popFile, nbWorldView);
+            if (!myPop.endFile) {
+                for (int i = 0; i < popToGenere.length; i++) {
+                    //country = (int) popToGenere[i][0];
+                    int nb = (int) popToGenere[i][1];
+                    count = count + nb;
+                    if ((int) popToGenere[i][2] == 1) { // inclusive
+                        countInclusif = countInclusif + nb;
+                    } else { // exclusive
+                        countExclusif = countExclusif + nb;
+                    }
+                    if (i == popToGenere.length - 1) {
+                        sizePop = count;
+                        inclusifs = countInclusif;
+                        exclusifs = countExclusif;
+                        count = 0;
+                    }
+                }
+            }
+        }
+        return myPop.endFile;
+    }
+
+    float[] maPosition;
+    float[] lowTol;
+    float[] highTol;
+
+    public void initAgentRandomized() {
+        // This is to randomize slightly the entering values of the cultural views profile 
+
+        float rand = -randomized + ((float) myRand.nextDouble() * (2 * randomized));
+        double prop = 0.0;
+        for (int i = 0; i < nbWorldView; i++) {
+            prop = (maPosition[i] - lowTol[i]) / (highTol[i] - lowTol[i]);
+            lowTol[i] = lowTol[i] + rand;
+            rand = -randomized + ((float) myRand.nextDouble() * (2 * randomized));
+            highTol[i] = highTol[i] + rand;
+            while (highTol[i] <= lowTol[i]) {
+                rand = -randomized + ((float) myRand.nextDouble() * (2 * randomized));
+                highTol[i] = highTol[i] + rand;
+            }
+            maPosition[i] = lowTol[i] + (float) (prop * (highTol[i] - lowTol[i]));
+        }
+        //
+    }
+
+    // compute the opinions of the agents on the others as an indicator
+    public void computeAgentsOpinions() {
+        for (int i = 0; i < sizePop; i++) {
+            for (int j = 0; j < sizePop; j++) {
+                population[i].opinionGlobalOnOthers[j] = (float) population[i].opinionOnOthers(population[j]);
+            }
+        }
+    }
+
+// compute the opinions of the agents on the others as an indicator
+    public double[] computeAgentsOpinions(int agentComputer, boolean knowTheOthersHasChanged) {
+        double[] op = new double[sizePop];
+        Arrays.fill(op, 1.0);
+        for (int i = 0; i < sizePop; i++) {
+            if (i != agentComputer) {
+                op[i] = (float) population[agentComputer].opinionOnOthers(population[i], knowTheOthersHasChanged);
+            }
+        }
+        return op;
+    }
+
+    // compute the opinions of one group for another group (or the same) one group by cultural dimension composed of people having their highest maPosition in the group dimension
+    public float[] computeAgentsOpinionsAvgStd(int dimGroupComputer, int dimOtherGroup, boolean knowTheOthersHasChanged) {
+        float op[] = new float[2];
+        Arrays.fill(op, 0.0f);
+        int divisor = 0;
+        for (int i = 0; i < sizePop; i++) {
+            if (population[i].mainCWWFromGroup() == dimGroupComputer) {
+                for (int j = 0; j < sizePop; j++) {
+                    if (population[j].mainCWWFromGroup() == dimOtherGroup) {
+                        op[0] = op[0] + (float) population[i].opinionOnOthers(population[j], knowTheOthersHasChanged);
+                        divisor++;
+                    }
+                }
+            }
+        }
+        op[0] = op[0] / (float) divisor; // computation of the average
+        for (int i = 0; i < sizePop; i++) {
+            if (population[i].mainCWWFromGroup() == dimGroupComputer) {
+                for (int j = 0; j < sizePop; j++) {
+                    if (population[j].mainCWWFromGroup() == dimOtherGroup) {
+                        op[1] = op[1] + (float) Math.pow(population[i].opinionOnOthers(population[j], knowTheOthersHasChanged) - op[0], 2.0);
+                    }
+                }
+            }
+        }
+        op[1] = (float) Math.sqrt(op[1] / (float) divisor); // computation of the average
+        return op;
+    }
+
+    // compute the opinions of one group for another group (or the same) one group by cultural dimension composed of people having their highest maPosition in the group dimension
+    public float[] computeAgentsOpinionsAvgStdSimplified(int dimGroupComputer, int dimOtherGroup, boolean knowTheOthersHasChanged) {
+        float op[] = new float[2];
+        Arrays.fill(op, 0.0f);
+        int divisor = 0;
+        int nbCouples = 0;
+        for (int i = 0; i < typeId.length; i++) {
+            if (population[typeId[i]].mainCWWFromGroup() == dimGroupComputer) {
+                for (int j = 0; j < typeId.length; j++) {
+                    //for (int j = 0; j < sizePop; j++) {
+                    if (population[typeId[j]].mainCWWFromGroup() == dimOtherGroup) {
+                        nbCouples = (population[typeId[i]].nbAgentThisType * population[typeId[j]].nbAgentThisType);
+                        op[0] = op[0] + nbCouples * (float) population[typeId[i]].opinionOnOthers(population[typeId[j]], knowTheOthersHasChanged);
+                        divisor = divisor + nbCouples;
+                    }
+                }
+            }
+        }
+        op[0] = op[0] / (float) divisor; // computation of the average
+        nbCouples = 0;
+        for (int i = 0; i < typeId.length; i++) {
+            if (population[typeId[i]].mainCWWFromGroup() == dimGroupComputer) {
+                for (int j = 0; j < typeId.length; j++) {
+                    if (population[typeId[j]].mainCWWFromGroup() == dimOtherGroup) {
+                        nbCouples = (population[typeId[i]].nbAgentThisType * population[typeId[j]].nbAgentThisType);
+                        op[1] = op[1] + nbCouples * (float) Math.pow(population[typeId[i]].opinionOnOthers(population[typeId[j]], knowTheOthersHasChanged) - op[0], 2.0);
+                    }
+                }
+            }
+        }
+        op[1] = (float) Math.sqrt(op[1] / (float) divisor); // computation of the average
+        return op;
+    }
+
+    // compute the opinions of one group for all the population
+    public float[] computeAgentsOpinionsAvgStdOfAll(int dimGroupComputer, boolean knowTheOthersHasChanged) {
+        float op[] = new float[2];
+        Arrays.fill(op, 0.0f);
+        int divisor = 0;
+        int nbCouples = 0;
+        for (int i = 0; i < typeId.length; i++) {
+            if (population[typeId[i]].mainCWWFromGroup() == dimGroupComputer) {
+                for (int j = 0; j < typeId.length; j++) {
+                    nbCouples = (population[typeId[i]].nbAgentThisType * population[typeId[j]].nbAgentThisType);
+                    op[0] = op[0] + nbCouples * (float) population[typeId[i]].opinionOnOthers(population[typeId[j]], knowTheOthersHasChanged);
+                    divisor = divisor + nbCouples;
+                }
+            }
+        }
+        op[0] = op[0] / (float) divisor; // computation of the average
+        nbCouples = 0;
+        for (int i = 0; i < typeId.length; i++) {
+            if (population[typeId[i]].mainCWWFromGroup() == dimGroupComputer) {
+                for (int j = 0; j < typeId.length; j++) {
+                    nbCouples = (population[typeId[i]].nbAgentThisType * population[typeId[j]].nbAgentThisType);
+                    op[1] = op[1] + nbCouples * (float) Math.pow(population[typeId[i]].opinionOnOthers(population[typeId[j]], knowTheOthersHasChanged) - op[0], 2.0);
+                }
+            }
+        }
+        op[1] = (float) Math.sqrt(op[1] / (float) divisor); // computation of the average
+        return op;
+    }
+
+    // compute the opinions of everyone one on one particular group
+    public float[] computeAgentsOpinionsAvgStdOnOneGroup(int dimGroupToEvaluate, boolean knowTheOthersHasChanged) {
+        float op[] = new float[2];
+        Arrays.fill(op, 0.0f);
+        int divisor = 0;
+        int nbCouples = 0;
+        for (int i = 0; i < typeId.length; i++) {
+            for (int j = 0; j < typeId.length; j++) {
+                if (population[typeId[j]].mainCWWFromGroup() == dimGroupToEvaluate) {
+                    nbCouples = (population[typeId[i]].nbAgentThisType * population[typeId[j]].nbAgentThisType);
+                    op[0] = op[0] + nbCouples * (float) population[typeId[i]].opinionOnOthers(population[typeId[j]], knowTheOthersHasChanged);
+                    divisor = divisor + nbCouples;
+                }
+            }
+        }
+        op[0] = op[0] / (float) divisor; // computation of the average
+        nbCouples = 0;
+        for (int i = 0; i < typeId.length; i++) {
+            for (int j = 0; j < typeId.length; j++) {
+                if (population[typeId[j]].mainCWWFromGroup() == dimGroupToEvaluate) {
+                    nbCouples = (population[typeId[i]].nbAgentThisType * population[typeId[j]].nbAgentThisType);
+                    op[1] = op[1] + nbCouples * (float) Math.pow(population[typeId[i]].opinionOnOthers(population[typeId[j]], knowTheOthersHasChanged) - op[0], 2.0);
+                }
+            }
+        }
+        op[1] = (float) Math.sqrt(op[1] / (float) divisor); // computation of the average
+        return op;
+    }
+
+    // compute the opinions the agents has on one agent : the source
+    public float computeAgentsOpinionsOnASource(Agent source) {
+        float opSource = 0.0f;
+        for (int i = 0; i < sizePop; i++) {
+            opSource = opSource + (float) population[i].opinionOnOthers(source);
+        }
+        return opSource / (float) (sizePop - 1);
+    }
+
+    public double computeAverageAgentsOpinions() { // except oneself
+        computeAgentsOpinions();
+        double count = 0;
+        for (int i = 0; i < sizePop; i++) {
+            for (int j = 0; j < sizePop; j++) {
+                if (i != j) {
+                    count = count + population[i].opinionGlobalOnOthers[j];
+                }
+            }
+        }
+        count = count / (double) (sizePop * (sizePop - 1));
+        return count;
+    }
+
+    public void initMessage() {
+        messages = new ArrayList<Message>();
+        float[][] popToGenere = myPop.lireExpDesignInitMessages(messageFile);
+        nbMessages = popToGenere.length;
+        int deb = 0;
+        String typeAgent = new String();
+        float maxAdher = Float.MIN_VALUE;
+        int dimAdhes = -1;
+        for (int i = 0; i < nbMessages; i++) {
+            maxAdher = Float.MIN_VALUE;
+            deb = 1;
+            int nbCWW = (int) ((popToGenere[i].length - 1) / 3.0f);
+            float[] adherence = new float[nbCWW];
+            float[] alow = new float[nbCWW];
+            float[] amax = new float[nbCWW];
+            for (int j = 0; j < nbCWW; j++) {
+                adherence[j] = popToGenere[i][deb + 1];
+                if (adherence[j] > maxAdher) {
+                    maxAdher = adherence[j];
+                    dimAdhes = i;
+                }
+                alow[j] = popToGenere[i][deb];
+                amax[j] = popToGenere[i][deb + 2];
+                deb = deb + 3;
+            }
+
+            if (popToGenere[i][0] == 1) {
+                typeAgent = "agressor";
+            } else {
+                typeAgent = "victim";
+            }
+            Agent source = new Agent(this, typeAgent, adherence, alow, amax, alpha, dimAdhes, 1);
+            messages.add(new Message(i + 1, (int) (popToGenere[i][0]), source));
+        }
+    }
+
+    public double computeDistanceAutrui(int i, boolean knowTheOthersHaveChanged) {
+        double[] opinions = computeAgentsOpinions(i, knowTheOthersHaveChanged);
+        double distanceAutrui = 0.0;
+        for (int z = 0; z < opinions.length; z++) {
+            if (z != i) {
+                distanceAutrui = distanceAutrui + Math.abs(1 - opinions[z]);
+            }
+        }
+        distanceAutrui = distanceAutrui / (double) (opinions.length - 1);
+        return distanceAutrui;
+    }
+
+    public double computeIntraGroupDistance(int i, boolean knowTheOthersHaveChanged) {
+        double distanceIntraGroup = 0.0;
+        int nbIndiv = 0;
+        for (int z = 0; z < sizePop; z++) {
+            if (population[z].mainCWWFromGroup() == population[i].mainCWWFromGroup()) {
+                distanceIntraGroup = distanceIntraGroup + (Math.abs(1.0 - population[i].opinionOnOthers(population[z], knowTheOthersHaveChanged)));
+                nbIndiv++;
+            }
+        }
+        distanceIntraGroup = distanceIntraGroup / (double) nbIndiv;
+        return distanceIntraGroup;
+    }
+
+    public double computeOpPop(int i, boolean knowTheOthersHaveChanged) { // compute the average opinion of one agent type over all the population
+        double[] opinions = computeAgentsOpinions(i, knowTheOthersHaveChanged);
+        double cumul = 0.0;
+        for (int z = 0; z < opinions.length; z++) {
+            cumul = cumul + opinions[z];
+        }
+        cumul = cumul / (double) (opinions.length);
+        return cumul;
+    }
+
+    public double[] computeOpGroup(int i, boolean knowTheOthersHaveChanged) { // compute the average opinions of one agent type over each groups of agent
+        double[] opinions = computeAgentsOpinions(i, knowTheOthersHaveChanged);
+        double[] cumul = new double[nbWorldView];
+        int[] nbByGroup = new int[nbWorldView];
+        Arrays.fill(nbByGroup, 0);
+        Arrays.fill(cumul, 0.0);
+        int temp = -1;
+        for (int z = 0; z < opinions.length; z++) {
+            temp = population[z].mainCWWFromGroup();
+            cumul[temp] = cumul[temp] + opinions[z];
+            nbByGroup[temp] = nbByGroup[temp] + 1;
+        }
+        for (int j = 0; j < nbWorldView; j++) {
+            cumul[j] = cumul[j] / (double) (nbByGroup[j]);
+        }
+        return cumul;
+    }
+
+    public void iterationWithAgentDetail(boolean knowTheOthersHaveChanged) {
+
+        // impression etat init
+        iteration = 0;
+        double opSourceBeforeMessage = -2.0f;
+        double opSourceAfterMessage = -2.0f;
+        double opSourceThreatBeforeMessage = -2.0f;
+        double opSourceThreatAfterMessage = -2.0f;
+        double opSourceMuslimInclusifBeforeMessage = -2.0f;
+        double opSourceMuslimInclusifAfterMessage = -2.0f;
+        double opSourceMuslimExclusifBeforeMessage = -2.0f;
+        double opSourceMuslimExclusifAfterMessage = -2.0f;
+        double opSourceAreligiousInclusifBeforeMessage = -2.0f;
+        double opSourceAreligiousInclusifAfterMessage = -2.0f;
+        double opSourceAreligiousExclusifBeforeMessage = -2.0f;
+        double opSourceAreligiousExclusifAfterMessage = -2.0f;
+        double opSourceChristiansInclusifBeforeMessage = -2.0f;
+        double opSourceChristiansInclusifAfterMessage = -2.0f;
+        double opSourceChristiansExclusifBeforeMessage = -2.0f;
+        double opSourceChristiansExclusifAfterMessage = -2.0f;
+
+        double distInGroupDontSeeOthers = -1000;
+        double distAutrui = -1000.0;
+        double opPop = 0.0;
+        double[] opGroup = new double[nbWorldView];
+        double stdPop;
+        double[] stdGroup = new double[nbWorldView];
+        Arrays.fill(opGroup, 0.0);
+        Arrays.fill(stdGroup, 0.0);
+
+        //recolter un individu de chaque type et les mettre dans loop ci-dessous
+        int[] typeId = new int[6];
+        Arrays.fill(typeId, -1);
+        typeId[0] = 0;
+        String lastType = population[0].type;
+        String group = population[0].group;
+        int count = 1;
+        for (int i = 1; i < sizePop; i++) {
+            if (!population[i].type.equalsIgnoreCase(lastType) || !population[i].group.equalsIgnoreCase(group)) {
+                //System.err.println(lastType + " " + population[i].type + " " + group + " " + population[i].group);
+                typeId[count] = i;
+                count++;
+                lastType = population[i].type;
+                group = population[i].group;
+            }
+        }
+        for (int z = 0; z < typeId.length; z++) { // everyone is impacted by the message except the "emetteur" who is not is the population
+            int i = typeId[z];
+            opSourceThreatBeforeMessage = population[i].opinionOnOthers(messages.get(0).emetteur);
+            opSourceMuslimInclusifBeforeMessage = population[i].opinionOnOthers(population[4]);
+            opSourceMuslimExclusifBeforeMessage = population[i].opinionOnOthers(population[5]);
+            opSourceChristiansInclusifBeforeMessage = population[i].opinionOnOthers(population[2]);
+            opSourceChristiansExclusifBeforeMessage = population[i].opinionOnOthers(population[3]);
+            opSourceAreligiousInclusifBeforeMessage = population[i].opinionOnOthers(population[0]);
+            opSourceAreligiousExclusifBeforeMessage = population[i].opinionOnOthers(population[1]);
+
+            distAutrui = computeDistanceAutrui(i, knowTheOthersHaveChanged);
+            distInGroupDontSeeOthers = computeIntraGroupDistance(i, knowTheOthersHaveChanged);
+            population[i].distAutruiInit = distAutrui;
+            opPop = computeOpPop(i, knowTheOthersHaveChanged);
+            opGroup = computeOpGroup(i, knowTheOthersHaveChanged);
+
+            opSourceThreatAfterMessage = opSourceThreatBeforeMessage;
+            opSourceMuslimInclusifAfterMessage = opSourceMuslimInclusifBeforeMessage;
+            opSourceMuslimExclusifAfterMessage = opSourceMuslimExclusifBeforeMessage;
+            opSourceChristiansInclusifAfterMessage = opSourceChristiansInclusifBeforeMessage;
+            opSourceChristiansExclusifAfterMessage = opSourceChristiansExclusifBeforeMessage;
+            opSourceAreligiousInclusifAfterMessage = opSourceAreligiousInclusifBeforeMessage;
+            opSourceAreligiousExclusifAfterMessage = opSourceAreligiousExclusifBeforeMessage;
+
+            writeImpactMessageWithAgentDetails(population[i], messages.get(0), (float) opSourceBeforeMessage, (float) opSourceAfterMessage,
+                    (float) opSourceThreatBeforeMessage, (float) opSourceThreatAfterMessage,
+                    (float) opSourceMuslimInclusifBeforeMessage, (float) opSourceMuslimInclusifAfterMessage,
+                    (float) opSourceMuslimExclusifBeforeMessage, (float) opSourceMuslimExclusifAfterMessage,
+                    (float) opSourceAreligiousInclusifBeforeMessage, (float) opSourceAreligiousInclusifAfterMessage,
+                    (float) opSourceAreligiousExclusifBeforeMessage, (float) opSourceAreligiousExclusifAfterMessage,
+                    (float) opSourceChristiansInclusifBeforeMessage, (float) opSourceChristiansInclusifAfterMessage,
+                    (float) opSourceChristiansExclusifBeforeMessage, (float) opSourceChristiansExclusifAfterMessage,
+                    (float) distAutrui, (float) distAutrui,
+                    (float) distInGroupDontSeeOthers, (float) distInGroupDontSeeOthers,
+                    (float) opPop, opGroup, knowTheOthersHaveChanged);
+        }
+        int mes = 0;
+        for (int it = 1; it <= nbIter; it++) {
+            iteration = it;
+            mes = mediaMessageWithAgentDetails(mes, it, knowTheOthersHaveChanged);
+        }
+    }
+
+    public void iteration(boolean knowTheOthersHaveChanged) {
+        // impression etat init
+        iteration = 0;
+        writeImpactMessageAVGSTD(messages.get(0), knowTheOthersHaveChanged);
+        // fin impression etat init     
+        int mes = 0;
+        for (int i = 1; i <= nbIter; i++) {
+            iteration = i;
+            mes = mediaMessage(mes, i, knowTheOthersHaveChanged); // send to agent I a value on agent J
+        }
+    }
+
+    public int mediaMessageWithAgentDetails(int mes, int iter, boolean knowTheOthersHaveChanged) {
+        int nextMes = mes;
+        if (mes < messages.size()) {
+            double opSourceBeforeMessage = -2.0f;
+            double opSourceAfterMessage = -2.0f;
+            double opSourceThreatBeforeMessage = -2.0f;
+            double opSourceThreatAfterMessage = -2.0f;
+            double opSourceMuslimInclusifBeforeMessage = -2.0f;
+            double opSourceMuslimInclusifAfterMessage = -2.0f;
+            double opSourceMuslimExclusifBeforeMessage = -2.0f;
+            double opSourceMuslimExclusifAfterMessage = -2.0f;
+            double opSourceAreligiousInclusifBeforeMessage = -2.0f;
+            double opSourceAreligiousInclusifAfterMessage = -2.0f;
+            double opSourceAreligiousExclusifBeforeMessage = -2.0f;
+            double opSourceAreligiousExclusifAfterMessage = -2.0f;
+            double opSourceChristiansInclusifBeforeMessage = -2.0f;
+            double opSourceChristiansInclusifAfterMessage = -2.0f;
+            double opSourceChristiansExclusifBeforeMessage = -2.0f;
+            double opSourceChristiansExclusifAfterMessage = -2.0f;
+
+            double distAutruiIfAllOthersAreMet = -1000.0; // see my change but also the change of others
+            double distAutruiJustEvolvingDueTheMessageImpact = -1000.0;; // only see my change, do not see the change of others
+            double distInGroupSeeOthers = -1000;
+            double distInGroupDontSeeOthers = -1000;
+            double opPop = 0.0;
+            double[] opGroup = new double[nbWorldView];
+            double stdPop;
+            double[] stdGroup = new double[nbWorldView];
+            Arrays.fill(opGroup, 0.0);
+            Arrays.fill(stdGroup, 0.0);
+
+            if (messages.get(mes).time == iter) {
+                for (int z = 0; z < typeId.length; z++) { // everyone is impacted by the message except the "emetteur" who is not is the population
+                    int i = typeId[z]; // the type of agent
+
+                    opSourceBeforeMessage = population[i].opinionOnOthers(messages.get(mes).emetteur);
+                    opSourceThreatBeforeMessage = population[i].opinionOnOthers(messages.get(0).emetteur);
+                    opSourceMuslimInclusifBeforeMessage = population[i].opinionOnOthers(population[4]);
+                    opSourceMuslimExclusifBeforeMessage = population[i].opinionOnOthers(population[5]);
+                    opSourceAreligiousInclusifBeforeMessage = population[i].opinionOnOthers(population[0]);
+                    opSourceAreligiousExclusifBeforeMessage = population[i].opinionOnOthers(population[1]);
+                    opSourceChristiansInclusifBeforeMessage = population[i].opinionOnOthers(population[2]);
+                    opSourceChristiansExclusifBeforeMessage = population[i].opinionOnOthers(population[3]);
+
+                    population[i].reactionToMessage(messages.get(mes).type, messages.get(mes).emetteur);
+                    distAutruiIfAllOthersAreMet = computeDistanceAutrui(i, !knowTheOthersHaveChanged);
+                    distAutruiJustEvolvingDueTheMessageImpact = computeDistanceAutrui(i, knowTheOthersHaveChanged);
+                    distInGroupSeeOthers = computeIntraGroupDistance(i, !knowTheOthersHaveChanged);
+                    distInGroupDontSeeOthers = computeIntraGroupDistance(i, knowTheOthersHaveChanged);
+                    opPop = computeOpPop(i, knowTheOthersHaveChanged);
+                    opGroup = computeOpGroup(i, knowTheOthersHaveChanged);
+
+                    opSourceAfterMessage = population[i].opinionOnOthers(messages.get(mes).emetteur);
+                    opSourceThreatAfterMessage = population[i].opinionOnOthers(messages.get(0).emetteur);
+                    opSourceMuslimInclusifAfterMessage = population[i].opinionOnOthers(population[4]);
+                    opSourceMuslimExclusifAfterMessage = population[i].opinionOnOthers(population[5]);
+                    opSourceAreligiousInclusifAfterMessage = population[i].opinionOnOthers(population[0]);
+                    opSourceAreligiousExclusifAfterMessage = population[i].opinionOnOthers(population[1]);
+                    opSourceChristiansInclusifAfterMessage = population[i].opinionOnOthers(population[2]);
+                    opSourceChristiansExclusifAfterMessage = population[i].opinionOnOthers(population[3]);
+                    writeImpactMessageWithAgentDetails(population[i], messages.get(mes), (float) opSourceBeforeMessage, (float) opSourceAfterMessage,
+                            (float) opSourceThreatBeforeMessage, (float) opSourceThreatAfterMessage,
+                            (float) opSourceMuslimInclusifBeforeMessage, (float) opSourceMuslimInclusifAfterMessage,
+                            (float) opSourceMuslimExclusifBeforeMessage, (float) opSourceMuslimExclusifAfterMessage,
+                            (float) opSourceAreligiousInclusifBeforeMessage, (float) opSourceAreligiousInclusifAfterMessage,
+                            (float) opSourceAreligiousExclusifBeforeMessage, (float) opSourceAreligiousExclusifAfterMessage,
+                            (float) opSourceChristiansInclusifBeforeMessage, (float) opSourceChristiansInclusifAfterMessage,
+                            (float) opSourceChristiansExclusifBeforeMessage, (float) opSourceChristiansExclusifAfterMessage,
+                            (float) distAutruiIfAllOthersAreMet, (float) distAutruiJustEvolvingDueTheMessageImpact,
+                            (float) distInGroupSeeOthers, (float) distInGroupDontSeeOthers,
+                            (float) opPop, opGroup, knowTheOthersHaveChanged);
+                }
+                nextMes = mes + 1;
+            }
+        }
+        return nextMes;
+    }
+
+    public int mediaMessage(int mes, int iter, boolean knowTheOthersHaveChanged) {
+        int nextMes = mes;
+        if (mes < messages.size()) {
+            if (messages.get(mes).time == iter) {
+                for (int i = 0; i < sizePop; i++) { // everyone is impacted by the message except the "emetteur" who is not is the population
+                    population[i].reactionToMessage(messages.get(mes).type, messages.get(mes).emetteur);
+                }
+                if (iter == 7) {
+                    writeImpactMessageAVGSTD(messages.get(0), knowTheOthersHaveChanged);
+                }
+                nextMes = mes + 1;
+            }
+        }
+        return nextMes;
+    }
+
+    public void writeImpactMessageWithAgentDetails(Agent receiver, Message mes, float opSourceBeforeMessage, float opSourceAfterMessage,
+            float opSourceThreatBeforeMessage, float opSourceThreatAfterMessage,
+            float opSourceMuslimInclusifBeforeMessage, float opSourceMuslimInclusifAfterMessage,
+            float opSourceMuslimExclusifBeforeMessage, float opSourceMuslimExclusifAfterMessage,
+            float opSourceAreligiousInclusifBeforeMessage, float opSourceAreligiousInclusifAfterMessage,
+            float opSourceAreligiousExclusifBeforeMessage, float opSourceAreligiousExclusifAfterMessage,
+            float opSourceChristiansInclusifBeforeMessage, float opSourceChristiansInclusifAfterMessage,
+            float opSourceChristiansExclusifBeforeMessage, float opSourceChristiansExclusifAfterMessage,
+            float distAutruiOtherAndMeChanged, float distAutruiOnlyMeChanged,
+            float distIntraGroupSeeOthers, float distIntraGroupSeeMeOnly,
+            float opPop, double[] opGroup, boolean knowsAboutOthers) {
+        //System.err.println("je passe dans ecrire avec detail ");
+        myPop.writResult.print(popFile + ";");
+        myPop.writResult.print(messageFile + ";");
+        myPop.writResult.print(nomExpe + ";");
+        printParametres();
+        myPop.writResult.print(iteration + ";");
+        myPop.writResult.print(receiver.nbAgentThisType + ";");
+        myPop.writResult.print(receiver.type + ";");
+        myPop.writResult.print(receiver.mainCWWFromGroup() + ";");
+        for (int i = 0; i < receiver.myCulture.length; i++) {
+            myPop.writResult.print(receiver.myCulture[i].alow + ";");
+            myPop.writResult.print(receiver.myCulture[i].maPosition + ";");
+            myPop.writResult.print(receiver.myCulture[i].amax + ";");
+        }
+        myPop.writResult.print(mes.type + ";");
+        myPop.writResult.print(mes.emetteur.type + ";");
+        myPop.writResult.print(mes.emetteur.mainCWWFromGroup() + ";");
+        for (int i = 0; i < mes.emetteur.myCulture.length; i++) {
+            myPop.writResult.print(mes.emetteur.myCulture[i].alow + ";");
+            myPop.writResult.print(mes.emetteur.myCulture[i].maPosition + ";");
+            myPop.writResult.print(mes.emetteur.myCulture[i].amax + ";");
+        }
+        myPop.writResult.print(opSourceBeforeMessage + ";");
+        myPop.writResult.print(opSourceAfterMessage + ";");
+        myPop.writResult.print(opSourceThreatBeforeMessage + ";");
+        myPop.writResult.print(opSourceThreatAfterMessage + ";");
+        myPop.writResult.print(opSourceMuslimInclusifBeforeMessage + ";");
+        myPop.writResult.print(opSourceMuslimInclusifAfterMessage + ";");
+        myPop.writResult.print(opSourceMuslimExclusifBeforeMessage + ";");
+        myPop.writResult.print(opSourceMuslimExclusifAfterMessage + ";");
+        myPop.writResult.print(opSourceAreligiousInclusifBeforeMessage + ";");
+        myPop.writResult.print(opSourceAreligiousInclusifAfterMessage + ";");
+        myPop.writResult.print(opSourceAreligiousExclusifBeforeMessage + ";");
+        myPop.writResult.print(opSourceAreligiousExclusifAfterMessage + ";");
+        myPop.writResult.print(opSourceChristiansInclusifBeforeMessage + ";");
+        myPop.writResult.print(opSourceChristiansInclusifAfterMessage + ";");
+        myPop.writResult.print(opSourceChristiansExclusifBeforeMessage + ";");
+        myPop.writResult.print(opSourceChristiansExclusifAfterMessage + ";");
+        myPop.writResult.print(distAutruiOnlyMeChanged + ";");
+        myPop.writResult.print(distAutruiOtherAndMeChanged + ";");
+        myPop.writResult.print(distIntraGroupSeeMeOnly + ";");
+        myPop.writResult.print(distIntraGroupSeeOthers + ";");
+        myPop.writResult.print(knowsAboutOthers + ";");
+        myPop.writResult.print(opPop + ";");
+        for (int i = 0; i < nbWorldView; i++) {
+            myPop.writResult.print((float) opGroup[i] + ";");
+        }
+        myPop.writResult.println();
+    }
+
+    public void writeImpactMessageAVGSTD(Message mes, boolean knowsAboutOthers) { // AVGSTD
+        myPop.writResult.print(popFile + ";");
+        myPop.writResult.print(messageFile + ";");
+        myPop.writResult.print(nomExpe + ";");
+        printParametres();
+        myPop.writResult.print(iteration + ";");
+        for (int z = 0; z < typeId.length; z++) {
+            myPop.writResult.print(population[typeId[z]].group + ";");
+            myPop.writResult.print(population[typeId[z]].type + ";");
+            myPop.writResult.print(population[typeId[z]].nbAgentThisType + ";");
+        }
+        float[] avgStd = new float[2];
+        Arrays.fill(avgStd, 0.0f);
+        // opinion of each group on another group
+        for (int a = 0; a < nbWorldView; a++) {
+            for (int b = 0; b < nbWorldView; b++) {
+                avgStd = computeAgentsOpinionsAvgStdSimplified(a, b, knowsAboutOthers);
+                myPop.writResult.print(new Float(avgStd[0]).toString().replace(".", ",") + ";");
+                myPop.writResult.print(new Float(avgStd[1]).toString().replace(".", ",") + ";");
+            }
+        }
+        // opinion of every one on each group
+        for (int a = 0; a < nbWorldView; a++) {
+            avgStd = computeAgentsOpinionsAvgStdOfAll(a, knowsAboutOthers);
+            myPop.writResult.print(new Float(avgStd[0]).toString().replace(".", ",") + ";");
+            myPop.writResult.print(new Float(avgStd[1]).toString().replace(".", ",") + ";");
+        }
+        // of the two other groups
+        for (int a = 0; a < nbWorldView; a++) {
+            avgStd = computeAgentsOpinionsAvgStdOnOneGroup(a, knowsAboutOthers);
+            myPop.writResult.print(new Float(avgStd[0]).toString().replace(".", ",") + ";");
+            myPop.writResult.print(new Float(avgStd[1]).toString().replace(".", ",") + ";");
+        }
+        myPop.writResult.println();
+    }
+
+    public void printParametres() {
+        for (int i = 0; i < parametres.length; i++) {
+            myPop.writResult.print(((new Float(parametres[i])).toString()).replace(".", ",") + ";");
+        }
+    }
+
+    public double computeTolerance(int culturalDim) { // compute the average tolerance width of everyone for a cultural dimension
+        double temp = 0;
+        double tol = 0;
+        for (int i = 0; i < sizePop; i++) {
+            temp = population[i].myCulture[culturalDim].amax - 0; // ne compte que la partie positive de la tolerance
+            if (temp > 0) {
+                tol = tol + temp;
+            }
+        }
+        tol = tol / (double) sizePop;
+        return tol;
+    }
+
+}
diff --git a/src/Tools.java b/src/Tools.java
new file mode 100644
index 0000000000000000000000000000000000000000..a9282ed4c32b05f8957b0c32513f31a3422135a1
--- /dev/null
+++ b/src/Tools.java
@@ -0,0 +1,254 @@
+
+import cern.colt.Arrays;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.List;
+import jxl.Cell;
+import jxl.Sheet;
+import jxl.Workbook;
+import jxl.read.biff.BiffException;
+
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+/**
+ *
+ * @author oumou-raby.dia
+ */
+public class Tools {
+
+    public boolean go;
+    public boolean endFile;
+    public PrintStream writResult;
+    public String messageFileName;
+    public String country; // give the name of the experiment
+
+    public Tools() {
+        go = true;
+    }
+
+    //Lecture des données d'initialisation des agents
+    public float[][] lireExpDesignInitPop(int firstLine, int endLine, String name, int nbDimCulturel) {
+        go = true;
+        float[][] myPop = new float[0][0];
+        Workbook workbook = null;
+        try {
+            /* Récupération du classeur Excel (en lecture) */
+            workbook = Workbook.getWorkbook(new File(name));
+            /* Un fichier excel est composé de plusieurs feuilles, on y accède de la manière suivante*/
+            Sheet sheet = workbook.getSheet(0);
+            int a = 0;
+            if (firstLine >= sheet.getRows()) {
+                endFile = true;
+                go = false;
+            } else {
+                myPop = new float[nbDimCulturel * 2][0];
+                for (int j = firstLine; j <= endLine; j++) {
+                    Cell[] lineExpe = sheet.getRow(j);
+                    myPop[a] = readLineInitPop(lineExpe, nbDimCulturel);
+                    a++;
+                }
+                go = false;
+            }
+            workbook.close();
+        } catch (BiffException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            if (workbook != null) {
+                /* On ferme le worbook pour libérer la mémoire */
+                workbook.close();
+            }
+        }
+        return myPop;
+    }
+
+    public float[] readLineInitPop(Cell[] lineExpe, int nbDimCult) {
+        float[] toGenere = new float[13];
+
+        String[] expe = new String[lineExpe.length];
+        for (int i = 0; i < lineExpe.length; i++) {
+            expe[i] = (lineExpe[i].getContents()).replaceAll(",", ".");
+        }
+
+        country = expe[0];
+        messageFileName = expe[1];
+        float taillePop = (new Integer(expe[2])).intValue();
+        float dimAdhesion = -1.0f;
+        if ((expe[3]).equals("areligious")) {
+            dimAdhesion = 2.0f;
+        } else if ((expe[3]).equals("christians")) {
+            dimAdhesion = 1.0f;
+        } else { // is muslim
+            dimAdhesion = 0.0f;
+        }
+        float partTypeInPop = (new Float(expe[4])).floatValue();
+        float type = (new Float(expe[5])).floatValue();
+        float CWWlow1 = (new Float(expe[6])).floatValue();
+        float CWWadherence1 = (new Float(expe[7])).floatValue();
+        float CWWup1 = (new Float(expe[8])).floatValue();
+        float CWWlow2 = (new Float(expe[9])).floatValue();
+        float CWWadherence2 = (new Float(expe[10])).floatValue();
+        float CWWup2 = (new Float(expe[11])).floatValue();
+        float CWWlow3 = (new Float(expe[12])).floatValue();
+        float CWWadherence3 = (new Float(expe[13])).floatValue();
+        float CWWup3 = (new Float(expe[14])).floatValue();
+
+        int nbDimAdhes = Math.round(taillePop * partTypeInPop);
+
+        toGenere[0] = dimAdhesion;
+        toGenere[1] = nbDimAdhes;
+        toGenere[2] = type;
+        toGenere[3] = CWWlow1;
+        toGenere[4] = CWWadherence1;
+        toGenere[5] = CWWup1;
+        toGenere[6] = CWWlow2;
+        toGenere[7] = CWWadherence2;
+        toGenere[8] = CWWup2;
+        toGenere[9] = CWWlow3;
+        toGenere[10] = CWWadherence3;
+        toGenere[11] = CWWup3;
+        toGenere[12] = taillePop;
+
+        return toGenere;
+    }
+
+    public int[] readLineInitPopOld(Cell[] lineExpe, int nbDimCult) {
+
+        int[] toGenere = new int[8];
+
+        String[] expe = new String[lineExpe.length];
+        for (int i = 0; i < lineExpe.length; i++) {
+            expe[i] = (lineExpe[i].getContents()).replaceAll(",", ".");
+        }
+
+        country = expe[0];
+        messageFileName = expe[1];
+        int taillePop = (new Integer(expe[2])).intValue();
+        int dimAdhesion = (new Integer(expe[3])).intValue();
+        float partTypeInPop = (new Float(expe[4])).floatValue();
+        float partInclusiveInType = (new Float(expe[5])).floatValue();
+        float partExclusiveInType = (new Float(expe[6])).floatValue();
+        float partExtremInInclusif = (new Float(expe[7])).floatValue();
+        float partExtremInExclusif = (new Float(expe[8])).floatValue();
+        int nbDimAdhes = (int) (taillePop * partTypeInPop);
+        int inclus = (int) (nbDimAdhes * partInclusiveInType);
+        int exclus = nbDimAdhes - inclus;
+        int inclusExtr = (int) (inclus * partExtremInInclusif);
+        int exclusExtr = (int) (exclus * partExtremInExclusif);
+
+        toGenere[0] = dimAdhesion;
+        toGenere[1] = nbDimAdhes;
+        toGenere[2] = inclus;
+        toGenere[3] = exclus;
+        toGenere[4] = inclusExtr;
+        toGenere[5] = exclusExtr;
+        toGenere[6] = taillePop;
+        toGenere[7] = nbDimCult;
+
+        return toGenere;
+    }
+
+    public void ecritureInFileSourceStudyFromDataAVGSTD(String nomFile) {
+        try {
+            writResult = new PrintStream(new FileOutputStream(new File(nomFile)));
+            writResult.print("popFile" + ";" + "messageFile" + ";" + "nomExpe" + ";" + "numReplique" + ";" + "randomizedInitCWW" + ";" + "alpha" + ";" + "epsilon" + ";" + "nbPoints" + ";" + "nbDimCWW" + ";");
+            writResult.print("iteration" + ";"
+                    
+                    + "GroupOfAgent(2=Areligious,1=Christians,0=Muslims" + ";" + "typeOfAgent" +";" + "numberOfAgentOfThisType(AreligiousInclusive)"+ ";"
+                    + "GroupOfAgent(2=Areligious,1=Christians,0=Muslims" + ";" + "typeOfAgent" +";" + "numberOfAgentOfThisType(AreligiousExclusive)"+ ";"
+                    + "GroupOfAgent(2=Areligious,1=Christians,0=Muslims" + ";" + "typeOfAgent" +";" + "numberOfAgentOfThisType(ChristiansInclusive)"+ ";"
+                    + "GroupOfAgent(2=Areligious,1=Christians,0=Muslims" + ";" + "typeOfAgent" +";" + "numberOfAgentOfThisType(ChristiansExclusive)"+ ";"
+                    + "GroupOfAgent(2=Areligious,1=Christians,0=Muslims" + ";" + "typeOfAgent" +";" + "numberOfAgentOfThisType(MuslimsInclusive)"+ ";"
+                    + "GroupOfAgent(2=Areligious,1=Christians,0=Muslims" + ";" + "typeOfAgent" +";" + "numberOfAgentOfThisType(MuslimsExclusive)"+ ";"
+                    + "AverageOpinionOfGroup0onGroup0" + ";" + "STDDevOpinionOfGroup0onGroup0" + ";" + "AverageOpinionOfGroup0onGroup1" + ";" + "STDDevOpinionOfGroup0onGroup1" + ";" + "AverageOpinionOfGroup0onGroup2" + ";" + "STDDevOpinionOfGroup0onGroup2" + ";"
+                    + "AverageOpinionOfGroup1onGroup0" + ";" + "STDDevOpinionOfGroup1onGroup0" + ";" + "AverageOpinionOfGroup1onGroup1" + ";" + "STDDevOpinionOfGroup1onGroup1" + ";" + "AverageOpinionOfGroup1onGroup2" + ";" + "STDDevOpinionOfGroup1onGroup2" + ";"
+                    + "AverageOpinionOfGroup2onGroup0" + ";" + "STDDevOpinionOfGroup2onGroup0" + ";" + "AverageOpinionOfGroup2onGroup1" + ";" + "STDDevOpinionOfGroup2onGroup1" + ";" + "AverageOpinionOfGroup2onGroup2" + ";" + "STDDevOpinionOfGroup2onGroup2" + ";"
+                    + "AverageOpinionOfGroup0OnAllTheAgents" + ";" + "STDDevOpinionOfGroup0OnAllTheAgents" + ";" + "AverageOpinionOfGroup1OnAllTheAgents" + ";" + "STDDevOpinionOfGroup1OnAllTheAgents" + ";" + "AverageOpinionOfGroup2OnAllTheAgents" + ";" + "STDDevOpinionOfGroup2OnAllTheAgents" + ";"
+                    + "AverageOpinionOfAllOnGroup0members" + ";" + "STDDevOpinionOfAllOnGroup0members" + ";" + "AverageOpinionOfAllOnGroup1members" + ";" + "STDDevOpinionOfAllOnGroup1members" + ";" + "AverageOpinionOfAllOnGroup2members" + ";" + "STDDevOpinionOfAllOnGroup2members" + ";");
+             writResult.println();
+        } catch (Exception e) {
+            System.err.println("Erreur création du fichier pour le résultat de l'algorithme : " + e);
+        }
+    }
+
+    public void ecritureInFileSourceStudyFromDataDetails(String nomFile) { // for the method : writeImpactMessageWithAgentDetails
+        try {
+            writResult = new PrintStream(new FileOutputStream(new File(nomFile)));
+            writResult.print("popFile" + ";" + "messageFile" + ";" + "nomExpe" + ";" + "numReplique" + ";" + "randomizedInitCWW" + ";" + "alpha" + ";" + "epsilon" + ";" + "nbPoints" + ";" + "nbDimCWW" + ";");
+            writResult.print("iteration" + ";" + "numberOfAgentOfThisType" + ";" + "typeOfAgent" + ";" + "GroupOfAgent(2=Areligious,1=Christians,0=Muslims" + ";"
+                    + "AgentCWW0Muslim low" + ";" + "AgentCWW0Muslim mostAcceptablePosition" + ";" + "AgentCWW0Muslim up" + ";"
+                    + "AgentCWW1Christian low" + ";" + "AgentCWW1Christian mostAcceptablePosition" + ";" + "AgentCWW1Christian up" + ";"
+                    + "AgentCWW2Areligious low" + ";" + "AgentCWW2Areligious mostAcceptablePosition" + ";" + "AgentCWW2Areligious up" + ";"
+                    + "messageType(1=threat)" + ";" + "sourceMessagetype" + ";" + "groupOfTheSourceMessage" + ";"
+                    + "sourceCWW0MuslimMuslim low" + ";" + "sourceCWW0Muslim mostAcceptablePosition" + ";" + "sourceCWW0Muslim up" + ";"
+                    + "sourceCWW1Christian low" + ";" + "sourceCWW1Christian mostAcceptablePosition" + ";" + "sourceCWW1Christian up" + ";"
+                    + "sourceCWW2Areligious low" + ";" + "sourceCWW2Areligious mostAcceptablePosition" + ";" + "sourceCWW2Areligious up" + ";"
+                    + "averageOpinionOfThisTypeOfAgentOnSourceBeforeMessage" + ";" + "averageOpinionOfThisTypeOfAgentOnSourceAfterMessage" + ";" + "averageOpinionOfThisTypeOfAgentOnSourceThreatBeforeMessage" + ";" + "averageOpinionOfThisTypeOfAgentOnSourceThreatAfterMessage" + ";"
+                    + "averageOpinionOfThisTypeOfAgentOnSourceMuslimInclusifBeforeMessage" + ";" + "averageOpinionOfThisTypeOfAgentOnSourceMuslimInclusifAfterMessage" + ";" + "averageOpinionOfThisTypeOfAgentOnSourceMuslimExclusifBeforeMessage" + ";"
+                    + "averageOpinionOfThisTypeOfAgentOnSourceMuslimExclusifAfterMessage" + ";" + "averageOpinionOfThisTypeOfAgentOnSourceAreligiousInclusifBeforeMessage" + ";" + "averageOpinionOfThisTypeOfAgentOnSourceAreligiousInclusifAfterMessage" + ";"
+                    + "averageOpinionOfThisTypeOfAgentOnSourceAreligiousExclusifBeforeMessage" + ";" + "averageOpinionOfThisTypeOfAgentOnSourceAreligiousExclusifAfterMessage" + ";" + "averageOpinionOfThisTypeOfAgentOnSourceChristiansInclusifBeforeMessage" + ";"
+                    + "averageOpinionOfThisTypeOfAgentOnSourceChristiansInclusifAfterMessage" + ";" + "averageOpinionOfThisTypeOfAgentOnSourceChristiansExclusifBeforeMessage" + ";" + "averageOpinionOfThisTypeOfAgentOnSourceChristiansExclusifAfterMessage" + ";"
+                    + "distAutruiOnlyMeChanged" + ";" + "distAutruiOtherAndMeChanged" + ";" + "distIntraGroupSeeMeOnly" + ";" + "distIntraGroupSeeOthers" + ";" + "knowsAboutOthers" + ";"
+                    + "averageOpinionOfThisTypeOfAgentOnEveryone" + ";" + "averageOpinionOfThisTypeOfAgentOnGroup0Muslim" + ";" + "averageOpinionOfThisTypeOfAgentOn1Christian" + ";" + "averageOpinionOfThisTypeOfAgentOnGroup2Areligious" + ";");
+            writResult.println();
+        } catch (Exception e) {
+            System.err.println("Erreur création du fichier pour le résultat de l'algorithme : " + e);
+        }
+    }
+
+    //label message, indiv source (ou pas), source type, source group, source cwws, opinion receiver on source avant message, opinion receiver on source après message
+    //Lecture des données d'initialisation des agents
+    public float[][] lireExpDesignInitMessages(String name) {
+
+        float[][] myMessages = new float[0][0];
+        Workbook workbook = null;
+        try {
+            /* Récupération du classeur Excel (en lecture) */
+            workbook = Workbook.getWorkbook(new File(name));
+            /* Un fichier excel est composé de plusieurs feuilles, on y accède de la manière suivante*/
+            Sheet sheet = workbook.getSheet(0);
+            int nbMessages = sheet.getRows() - 1;
+            myMessages = new float[nbMessages][0];
+            for (int j = 0; j < nbMessages; j++) {
+                Cell[] lineExpe = sheet.getRow(j + 1);
+                myMessages[j] = readLineInitMessage(lineExpe);
+            }
+        } catch (BiffException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            if (workbook != null) {
+                /* On ferme le worbook pour libérer la mémoire */
+                workbook.close();
+            }
+        }
+        return myMessages;
+    }
+
+    public float[] readLineInitMessage(Cell[] lineExpe) {
+
+        float[] toGenere = new float[lineExpe.length];
+
+        String[] expe = new String[lineExpe.length];
+        for (int i = 0; i < lineExpe.length; i++) {
+            expe[i] = (lineExpe[i].getContents()).replaceAll(",", ".");
+        }
+        toGenere[0] = 2; // 2 is a compassion message
+        if (expe[0].equals(new String("threat"))) {
+            toGenere[0] = 1; // 1 is a threat
+        }
+        for (int i = 1; i < lineExpe.length; i++) {
+            toGenere[i] = (new Float(expe[i])).floatValue(); // series of triplets : low CWW, adherence CWW, up CWW to characteriste the cultural world view of the source
+        }
+        return toGenere;
+    }
+
+}