Commits

Anonymous committed c113eda

letzter stand

Comments (0)

Files changed (14)

File contents unchanged.
File contents unchanged.
File contents unchanged.

nbproject/build-impl.xml

             <attribute default="${build.classes.dir}" name="destdir"/>
             <sequential>
                 <fail unless="javac.includes">Must set javac.includes</fail>
-                <pathconvert pathsep="," property="javac.includes.binary">
+                <pathconvert pathsep="${line.separator}" property="javac.includes.binary">
                     <path>
                         <filelist dir="@{destdir}" files="${javac.includes}"/>
                     </path>
                     <globmapper from="*.java" to="*.class"/>
                 </pathconvert>
+                <tempfile deleteonexit="true" property="javac.includesfile.binary"/>
+                <echo file="${javac.includesfile.binary}" message="${javac.includes.binary}"/>
                 <delete>
-                    <files includes="${javac.includes.binary}"/>
+                    <files includesfile="${javac.includesfile.binary}"/>
                 </delete>
+                <delete file="${javac.includesfile.binary}"/>
             </sequential>
         </macrodef>
     </target>

nbproject/genfiles.properties

 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
 # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
 nbproject/build-impl.xml.data.CRC32=48b44add
-nbproject/build-impl.xml.script.CRC32=7812f70e
-nbproject/build-impl.xml.stylesheet.CRC32=f33e10ff@1.38.2.45
+nbproject/build-impl.xml.script.CRC32=949a77f3
+nbproject/build-impl.xml.stylesheet.CRC32=229523de@1.38.3.45

nbproject/project.properties

 javac.deprecation=false
 javac.processorpath=\
     ${javac.classpath}
-javac.source=1.5
-javac.target=1.5
+javac.source=1.6
+javac.target=1.6
 javac.test.classpath=\
     ${javac.classpath}:\
     ${build.classes.dir}:\
-    ${libs.junit.classpath}:\
     ${libs.junit_4.classpath}
 javac.test.processorpath=\
     ${javac.test.classpath}

nbproject/project.xml

File contents unchanged.

src/promotionModel/MarketPenetrationChart.java

+package promotionModel;
+
+import eawag.chart.Chart;
+import eawag.model.Agent;
+import java.util.ArrayList;
+
+/**
+ *
+ * @author chwassmuth
+ */
+public class MarketPenetrationChart extends Chart {
+
+    public Product product;
+    private int numAgents = 0;
+
+    public MarketPenetrationChart(Product p) {
+        setHTitle("Time");
+        setVTitle("market Penetration");
+        setComment("market Penetration for Product " + p.getSerno());
+        product = p;
+    }
+
+    @Override
+    public void condition() {
+        super.condition();
+
+        if (numAgents == 0) {
+            ArrayList<Agent> agents = new ArrayList<Agent>(getTop().getChilds());
+            for (Agent a : agents) {
+                if (a instanceof NetworkController) {
+                    numAgents = ((NetworkController) a).getChildCount();
+                    break;
+                }
+            }
+
+        }
+        this.lineTo(product.getSerno(), TYPE_LINE, getTop().getTime(), product.getMarketPenetration());
+    }
+}

src/promotionModel/NetworkController.java

 package promotionModel;
 
 import eawag.model.Swarm;
+import java.util.Random;
 
 /**
  *
  */
 public class NetworkController extends Swarm {
 
-    public int numPersons;
-    public int seeds;
-    public float pCampain;
-    public int adopted;
-    public int lastAdopted;
-    public float marketPenetration;
-    public float takeoffThreashold;
-    public float gamma;
-    public int numShortcuts;
+    private int numPersons = 3000;
+    private Swarm products;
+    private double percentShortcuts;
+    private int range = 2;
 
+    public int getNumPersons() {
+        return numPersons;
+    }
+
+    public void setNumPersons(int numPersons) {
+        this.numPersons = numPersons;
+    }
+
+    public double getPercentShortcuts() {
+        return percentShortcuts;
+    }
+
+    public void setPercentShortcuts(double percentShortcuts) {
+        this.percentShortcuts = percentShortcuts;
+    }
+
+    public Swarm getProducts() {
+        return products;
+    }
+
+    public void setProducts(Swarm products) {
+        this.products = products;
+    }
+
+    public int getRange() {
+        return range;
+    }
+
+    public void setRange(int range) {
+        this.range = range;
+    }
 
     @Override
     public void condition() {
         if (getTop().getTime() == 0) {
             generateAgents();
             linkAgents();
+            if (products != null) {
+                setProducts();
+            }
         }
-        System.out.println(child.length);
-        System.out.println(_child.length);
     }
 
     private void generateAgents() {
             Person p = new Person();
             p.join(this);
         }
+
     }
 
     private void linkAgents() {
-        for (int i = 0; i < numPersons; i++) {
-            int next = (i + 1) % numPersons;
-            int nextNext = (i + 2) % numPersons;
+        range = range < 1 ? 1 : range;
 
+        for (int i = 1; i <= range; i++) {
+            for (int j = 0; j < numPersons; j++) {
+                int next = (j + i) % numPersons;
 
-            Person aktualPerson = ((Person) this.getChildAt(i));
-            Person nextPerson = ((Person) this.getChildAt(next));
+                Person aktualPerson = ((Person) this.getChildAt(j));
+                Person nextPerson = ((Person) this.getChildAt(next));
 
-            aktualPerson.addLink(nextPerson);
-            nextPerson.addLink(aktualPerson);
+                aktualPerson.addLink(nextPerson);
+                nextPerson.addLink(aktualPerson);
 
-            Person nextNextPerson = ((Person) this.getChildAt(nextNext));
-
-            aktualPerson.addLink(nextNextPerson);
-            nextNextPerson.addLink(aktualPerson);
-
+            }
+        }
+        if (percentShortcuts < 0.01) {
+            percentShortcuts = 0.01;
+        }
+        if (percentShortcuts > 0.1) {
+            percentShortcuts = 0.1;
         }
 
-        //TODO: Shortcuts
+        int numShortcuts = (int) (numPersons * percentShortcuts);
+        for (int i = 0; i < numShortcuts; i++) {
+            Random rand = getTop().getRandom();
+
+            //doubled links allowed (Newman and Watts)
+            int zz1 = rand.nextInt(numPersons);
+            int zz2 = rand.nextInt(numPersons);
+
+            Person person1 = (Person) getChildAt(zz1);
+            Person person2 = (Person) getChildAt(zz2);
+
+            person1.addLink(person2);
+            person2.addLink(person1);
+        }
+    }
+
+    private void setProducts() {
+        int count = products.getChildCount();
+        for (int i = 0; i < count; i++) {
+            Product p = (Product) products.getChildAt(i);
+            for (int j = 0; j < numPersons; j++) {
+
+                ((Person) this.getChildAt(j)).addProduct(p);
+            }
+            // setting the seeds
+            int numAdopted = 0;
+            int numSeeds = (int) (p.getSeeds() * numPersons);
+            while (numSeeds > numAdopted) {
+                Random rand = getTop().getRandom();
+                Person person = (Person) this.getChildAt(rand.nextInt(numPersons));
+
+                ProductAdoption a = ((ProductAdoption) person.getChildAt(i));
+
+                if (!a.getAdopted() && rand.nextBoolean()) {
+                    a.setAdopted();
+                    a.set_Adopted();
+
+                    numAdopted++;
+                }
+
+
+            }
+            p.setAdopted(numAdopted);
+        }
+
+
     }
 }

src/promotionModel/Person.java

-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
 package promotionModel;
 
 import eawag.model.Swarm;
+import java.util.ArrayList;
 import java.util.LinkedList;
+import java.util.Random;
 
 /**
  *
 public class Person extends Swarm {
 
     private LinkedList<Person> links;
-    private LinkedList<ProductAdoption> products;
-    private LinkedList<ProductAdoption> _products;
 
     public Person() {
-        this(new LinkedList<Person>(), new LinkedList<ProductAdoption>());
+        links = new LinkedList<Person>();
     }
 
     public Person(LinkedList<ProductAdoption> products) {
 
     public Person(LinkedList<Person> links, LinkedList<ProductAdoption> products) {
         super();
-        this.links = links;
-        this.products = products;
+        for (ProductAdoption p : products) {
+            p.join(this);
+        }
         ProductAdoption p = new ProductAdoption();
         p.setBeta(12.0f);
         products.add(p);
         p.join(this);
     }
 
+    public LinkedList<Person> getLinks() {
+        return links;
+    }
+
     public void setLinks(LinkedList<Person> links) {
         this.links = links;
     }
         links.add(p);
     }
 
-    public void setProducts(LinkedList<ProductAdoption> products) {
-        this.products = products;
+    @Override
+    public void action() {
+        ArrayList<ProductAdoption> products = new ArrayList<ProductAdoption>(this.getChilds());
+        for (ProductAdoption p : products) {
+            int count = 0;
+            for (Person person : links) {
+                if (person.adoptedProduct(p.getProduct())) {
+                    count++;
+                }
+            }
+
+            Product product = p.getProduct();
+            int step = getTop().getTime();
+
+            boolean campaign = p.isReceiviedCampaign();
+
+            if (product.getCampainStart() <= step // or a campain started...
+                    && product.getCampainStop() >= step // ..and didn't end..
+                    && getTop().getRandom().nextDouble() <= product.getpCampain()) {
+                campaign = true;
+                if (product.isForgetsCampaign()) {
+                    p.setReceiviedCampaign();
+                }
+            }
+
+            if (count > 0 || campaign) {// if at least one Neighbour has adopted or received campaign
+                adoptProduct(p, count);
+            }
+        }
     }
 
-    public void addProduct(ProductAdoption p) {
-        products.add(p);
+    /**
+     * Transforms a Gaussian from N(0,1) to a N(mean, variance)
+     * @param gaussian
+     * @param mean
+     * @param variance
+     * @return
+     */
+    private double transformGaussian(double gaussian, double mean, double variance) {
+        //return (gaussian - mean) / Math.sqrt(variance);
+        assert (gaussian * Math.sqrt(variance) + mean > 0);
+        return gaussian * Math.sqrt(variance) + mean;
     }
 
-    @Override
-    public void condition() {
-        super.condition();
-        _products = (LinkedList<ProductAdoption>) products.clone();
+    public void addProduct(Product p) {
+        Random rand = getTop().getRandom();
+
+        double beta = transformGaussian(rand.nextGaussian(), p.getBetaMean(), p.getBetaVariance());
+        double influence = transformGaussian(rand.nextGaussian(), p.getInfluenceMean(), p.getInfluenceVariance());
+
+        ProductAdoption pa = new ProductAdoption(beta, influence,
+                rand.nextFloat(),
+                rand.nextFloat(),
+                p);
+
+        pa.join(this);
     }
 
-    public ProductAdoption getProduct() {
-        return products.getFirst();
+    /**
+     * Checks if Person adopted given Product
+     * @param p
+     * @return
+     */
+    public boolean adoptedProduct(Product p) {
+        ArrayList<ProductAdoption> products = new ArrayList<ProductAdoption>(this.getChilds());
+
+        for (ProductAdoption product : products) {
+            if (product.getProduct() == p && product.get_Adopted()) {
+                return true;
+            }
+        }
+        return false;
     }
 
-    @Override
-    public void action() {
-        ProductAdoption prod = products.getFirst();
-        prod.setBeta(prod.getBeta() + 1);
+    private void adoptProduct(ProductAdoption pa, int adopters) {
+        if (!pa.get_Adopted()) { // no need to calculate if already adopted
+            // a = adopters/(adopters + non adopters)
+            double a = adopters / links.size();
+            //*
+            // x = a >= h -> 1
+            double x = a >= pa.getInfluenceThreshold() ? 1 : 0;
+            // y = q >= p -> 1
+            double y = pa.getProduct().getQuality() >= pa.getIndividualPreference() ? 1 : 0;
 
-        System.out.println("product[1]: "+prod.getBeta());
-        System.out.println("product[1]: "+_products.getFirst().getBeta());
-        // TODO: Fill me
+            double beta = pa.getBeta();
+
+            double u = (beta * x) + ((1 - beta) * y);
+
+            /* // From the original model
+            double beta = pa.getBeta();
+            double qe50 = Math.pow(0.5, 50);
+            double stufenfunktion = qe50 / (qe50 + Math.pow(pa.getIndividualPreference(), 50));
+            
+            double u = (beta * stufenfunktion) + (1 - beta) * a;
+             */
+            if (u >= pa.getMinimalSatisfaction()) {
+                pa.setAdopted();
+            }
+        }
     }
 }

src/promotionModel/Product.java

+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package promotionModel;
+
+import eawag.model.Agent;
+import eawag.model.Swarm;
+import java.util.ArrayList;
+
+/**
+ *
+ * @author chwassmuth
+ */
+public class Product extends Agent {
+
+    private NetworkController network;
+    private double seeds;               // Percentage of the Population recieving the Product
+    private double pCampain;            // probability campain reaches an Agent
+    private double marketPenetration;
+    private double takeoffThreashold;
+    private double quality;             // q
+    private double gamma;               // shapes the market Penetration
+    private int adopted;                // Number of Agents adopted this Product (S_t)
+    private int lastAdopted;            // Number of Agents adopted this Product in last Step (S_t-1)
+    private int campainStart = -1;
+    private int campainStop = -1;
+    private boolean forgetsCampaign = true;
+    
+    private double betaMean;
+    private double betaVariance;
+    private double influenceMean;
+    private double influenceVariance;
+    private int resets = 0;          // help for synchronizing
+
+    public void setBetaMean(double BetaMean) {
+        this.betaMean = BetaMean;
+    }
+
+    public void setBetaVariance(double BetaVariance) {
+        this.betaVariance = BetaVariance;
+    }
+
+    public void setInfluenceMean(double InfluenceMean) {
+        this.influenceMean = InfluenceMean;
+    }
+
+    public void setInfluenceVariance(double InfluenceVariance) {
+        this.influenceVariance = InfluenceVariance;
+    }
+
+    public void setAdopted(int adopted) {
+        this.adopted = adopted;
+    }
+
+    public void setCampainStart(int campainStart) {
+        this.campainStart = campainStart;
+    }
+
+    public void setCampainStop(int campainStop) {
+        this.campainStop = campainStop;
+    }
+
+    public void setForgetsCampaign(boolean forgetsCampaign) {
+        this.forgetsCampaign = forgetsCampaign;
+    }
+
+    public void setGamma(double gamma) {
+        this.gamma = gamma;
+    }
+
+    public void setLastAdopted(int lastAdopted) {
+        this.lastAdopted = lastAdopted;
+    }
+
+    public void setMarketPenetration(double marketPenetration) {
+        this.marketPenetration = marketPenetration;
+    }
+
+    public void setpCampain(double pCampain) {
+        this.pCampain = pCampain;
+    }
+
+    public void setQuality(double quality) {
+        this.quality = quality;
+    }
+
+    public void setResets(int resets) {
+        this.resets = resets;
+    }
+
+    public void setSeeds(double seeds) {
+        this.seeds = seeds;
+    }
+
+    public void setTakeoffThreashold(double takeoffThreashold) {
+        this.takeoffThreashold = takeoffThreashold;
+    }
+
+    public double getBetaMean() {
+        return betaMean;
+    }
+
+    public double getBetaVariance() {
+        return betaVariance;
+    }
+
+    public double getInfluenceMean() {
+        return influenceMean;
+    }
+
+    public double getInfluenceVariance() {
+        return influenceVariance;
+    }
+
+    public int getAdopted() {
+        return adopted;
+    }
+
+    public int getCampainStart() {
+        return campainStart;
+    }
+
+    public int getCampainStop() {
+        return campainStop;
+    }
+
+    public boolean isForgetsCampaign() {
+        return forgetsCampaign;
+    }
+
+    public double getGamma() {
+        return gamma;
+    }
+
+    public int getLastAdopted() {
+        return lastAdopted;
+    }
+
+    public double getMarketPenetration() {
+        return marketPenetration;
+    }
+
+    public double getpCampain() {
+        return pCampain;
+    }
+
+    public double getQuality() {
+        return quality;
+    }
+
+    public int getResets() {
+        return resets;
+    }
+
+    public double getSeeds() {
+        return seeds;
+    }
+
+    public double getTakeoffThreashold() {
+        return takeoffThreashold;
+    }
+    
+
+    @Override
+    public void condition() {
+        super.condition();
+
+        if (getTop().getTime() == 0) {
+            ArrayList<Agent> agents = new ArrayList<Agent>(getTop().getChilds());
+
+            if (network == null) {
+                for (Agent a : agents) {
+                    if (a instanceof NetworkController) {
+                        network = ((NetworkController) a);
+                        break;
+                    }
+                }
+            }
+
+            Swarm s = null;
+
+            for (Agent a : agents) {
+                if (a instanceof Swarm && a.getSerno().equals("Graphs")) {
+                    s = (Swarm) a;
+                }
+            }
+
+
+            if (s == null) {
+                s = new Swarm();
+                s.setSerno("Graphs");
+                s.join(getTop());
+            }
+            new MarketPenetrationChart(this).join(s);
+        }
+
+        marketPenetration = (double)adopted / network.getNumPersons();
+    }
+}

src/promotionModel/ProductAdoption.java

-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
 package promotionModel;
 
 import eawag.model.Agent;
  */
 public class ProductAdoption extends Agent {
 
-    private float beta;
-    private float influence_threshold;
-    private float individual_preference;
-    private float minimal_satisfaction;
+    private double beta;                 // wichtungsfaktor
+    private double influenceThreshold;   // h
+    private double individualPreference; // p
+    private double minimalSatisfaction;  // U_min
+    private Product product;
     private boolean adopted;
     private boolean _adopted;
+    private boolean receiviedCampaign;
 
     public ProductAdoption() {
     }
 
-    public ProductAdoption(float beta, float influence_threshold, float individual_preference, float minimal_satisfaction, boolean adopted) {
+    public ProductAdoption(Product product) {
+        this.product = product;
+    }
+
+        public ProductAdoption(double beta, double influenceThreshold,
+            double individualPreference,
+            double minimalSatisfaction, Product product) {
+            this(beta, influenceThreshold, individualPreference, minimalSatisfaction, product, false);
+    }
+
+    public ProductAdoption(double beta, double influenceThreshold,
+            double individualPreference,
+            double minimalSatisfaction, Product product,
+            boolean adopted) {
         this.beta = beta;
-        this.influence_threshold = influence_threshold;
-        this.individual_preference = individual_preference;
-        this.minimal_satisfaction = minimal_satisfaction;
+        this.influenceThreshold = influenceThreshold;
+        this.individualPreference = individualPreference;
+        this.minimalSatisfaction = minimalSatisfaction;
+        this.product = product;
         this.adopted = adopted;
+        this._adopted = adopted;
     }
 
     public ProductAdoption(ProductAdoption product) {
         beta = product.beta;
-        influence_threshold = product.influence_threshold;
-        individual_preference = product.individual_preference;
-        minimal_satisfaction = product.minimal_satisfaction;
+        influenceThreshold = product.influenceThreshold;
+        individualPreference = product.individualPreference;
+        minimalSatisfaction = product.minimalSatisfaction;
         adopted = product.adopted;
     }
 
-    public void setAdopted(boolean adopted) {
-        this.adopted = adopted;
+    public void setAdopted() {
+        this.adopted = true;
     }
 
-    public void setBeta(float beta) {
+    public void set_Adopted() {
+        this._adopted = true;
+    }
+
+    public void setBeta(double beta) {
         this.beta = beta;
     }
 
-    public void setIndividual_preference(float individual_preference) {
-        this.individual_preference = individual_preference;
+    public void setIndividualPreference(double individual_preference) {
+        this.individualPreference = individual_preference;
     }
 
-    public void setInfluence_threshold(float influence_threshold) {
-        this.influence_threshold = influence_threshold;
+    public void setInfluenceThreshold(double influence_threshold) {
+        this.influenceThreshold = influence_threshold;
     }
 
-    public void setMinimal_satisfaction(float minimal_satisfaction) {
-        this.minimal_satisfaction = minimal_satisfaction;
+    public void setMinimalSatisfaction(double minimal_satisfaction) {
+        this.minimalSatisfaction = minimal_satisfaction;
     }
 
-    public boolean isAdopted() {
+    public boolean getAdopted() {
         return adopted;
     }
 
-    public float getBeta() {
+    public boolean get_Adopted() {
+        return _adopted;
+    }
+
+    public double getBeta() {
         return beta;
     }
 
-    public float getIndividual_preference() {
-        return individual_preference;
+    public double getIndividualPreference() {
+        return individualPreference;
     }
 
-    public float getInfluence_threshold() {
-        return influence_threshold;
+    public double getInfluenceThreshold() {
+        return influenceThreshold;
     }
 
-    public float getMinimal_satisfaction() {
-        return minimal_satisfaction;
+    public double getMinimalSatisfaction() {
+        return minimalSatisfaction;
     }
 
+    public Product getProduct() {
+        return product;
+    }
+
+    public boolean isReceiviedCampaign() {
+        return receiviedCampaign;
+    }
+
+    public void setReceiviedCampaign() {
+        this.receiviedCampaign = true;
+    }
+
+
+
     @Override
     public void condition() {
         super.condition();
 
+        if (product.getResets() < getTop().getTime()) {
+            product.setLastAdopted(product.getAdopted());
+            product.setResets(product.getResets()+1);
+        }
+
+        if (adopted && !_adopted) {
+
+            product.setAdopted(product.getAdopted()+1);
+        }
+
+
         _adopted = adopted;
     }
 }
   encoding = "cvid"
   content = "video.quicktime"
   quality = 0.5
-  gensym = 1
+  gensym = 3
   stepPlay = 40
   refreshSeek = 40
   fin = 10
   max = 10
   nsel = (java.lang.String[]
-    "NetworkController0")
+    @0:"NetworkController0")
   nexp = (java.lang.String[]
-    "_root")
+    "_root"
+    @0)
   simulatorHeight = 600
   simulatorWidth = 900
   errorDividerLocation = 420
 (promotionModel.NetworkController
   active = true
   randomize = false
-  numShortcuts = 0
-  gamma = 0.0
-  takeoffThreashold = 0.0
-  marketPenetration = 0.0
+  range = 2
+  percentShortcuts = 0.01
   lastAdopted = 0
   adopted = 0
-  pCampain = 0.0
-  seeds = 0
-  numPersons = 6)
+  products = ()
+  numPersons = 200)
+  _BEGIN_
+  _END_
+Swarm2
+(eawag.model.Swarm
+  active = true
+  randomize = false)
   _BEGIN_
   _END_
 _END_
+(eawag.model.Parameter
+  encoding = "cvid"
+  content = "video.quicktime"
+  quality = 0.5
+  gensym = 1
+  stepPlay = 40
+  refreshSeek = 40
+  fin = 10
+  max = 10
+  nsel = (java.lang.String[]
+    "Product0")
+  nexp = (java.lang.String[]
+    "Products"
+    "_root")
+  simulatorHeight = 600
+  simulatorWidth = 900
+  errorDividerLocation = 420
+  treeDividerLocation = 170
+  descriptionDividerLocation = 300
+  showDescription = false
+  hidetools = false
+  showform = false
+  hidetree = false
+  hideerror = false
+  hideexec = false
+  hideedit = false)
+Persons/Generator
+(promotionModel.NetworkController
+  active = true
+  randomize = false
+  range = 2
+  percentShortcuts = 0.01
+  products = Products
+  numPersons = 5000)
+  _BEGIN_
+  _END_
+Products
+(eawag.model.Swarm
+  active = true
+  randomize = false)
+  _BEGIN_
+  Product0
+  (promotionModel.Product
+    active = true
+    forgetsCampaign = true
+    resets = 0
+    influenceVariance = 0.01
+    influenceMean = 0.3
+    betaVariance = 0.01
+    betaMean = 0.9
+    campainStop = 60
+    campainStart = 0
+    lastAdopted = 0
+    adopted = 0
+    gamma = 0.0
+    quality = 0.5
+    takeoffThreashold = 0.0
+    marketPenetration = 0.0
+    pCampain = 0.0010
+    seeds = 0.01
+    network = ())
+  _END_
+_END_