-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Attached is a program I wrote to play with reliability factors...
The results, with A, B, C, and D mentioned in the previous post and all
the same data, run over a month at 5 requests per hour:

A:0.89 B:0.197 C:0.027 D:0.0 

One problem seems to be that halving the factor is a mighty punishment.  A
responds 95% of the time, but those 5% send it down pretty
fast.  Fortunately it recovers pretty fast as well, so this probably isn't
much of a problem.  

B does in fact hover between about 10 and 20% most of the time, as
expected.  C drops quickly to around 10% in an hour, but falls slower
after that as its not selected often because of its low reliablity.  I
think this is probably good, it means we don't give up entirely on C, but
we don't select it very often either.  The other good thing about C is
that it climbs back to 100% fairly quickly during the day.

D, as expected, drops to 0 within a few hours, and never recovers.

The algorithm needs some tweaking, but I think it has some nice
characteristics.

Thoughts?

        Scott


- ------
import java.util.*;

public class Playground {
    int timeOfDay, requestsPerHour;
    double reward, punishment;

    Vector contestants;

    public Playground(int rph, double reward, double punishment) {
        requestsPerHour=rph;
        this.reward=reward;
        this.punishment=punishment;
        contestants=new Vector();
    }

    public void add(Contestant c) {
        contestants.addElement(c);
    }

    public void remove(Contestant c) {
        contestants.removeElement(c);
    }

    public void run() {
        for (float t=0; t<24; t+=(1/(float)requestsPerHour)) {

            for (int i=0; i<requestsPerHour; i++) {
            System.out.print("t="+Contestant.prettify(t)+"\t");
            for (int x=0; x<contestants.size(); x++) {
                Contestant c=(Contestant)contestants.elementAt(x);
                System.out.print(c.name+":"+c.prettify(c.reliability)+" ");
            }
            System.out.println();

                Contestant c=null;
                do {
                    int cselect=(int)(Math.random()*contestants.size());
                    c=(Contestant)contestants.elementAt(cselect);
                } while (!c.picked());

                boolean connectResult=c.connect(t);
                if (connectResult) 
                    c.reliability=Math.min(c.reliability+reward, 1);
                else
                    c.reliability*=punishment;
            }
        }
    }

    public static void main(String[] args) throws Exception {
        //A is up 24 hours a day
        Contestant A=
            new Contestant("A", 1, 0.95, 
                           new int[][] {{0,24}});
        //B is up 24 hours a day, but for whatever reason only responds
        //80% of the time
        Contestant B=
            new Contestant("B", 1, 0.80,
                           new int[][] {{0,24}});
        //C is reliable, but is only up during the day.
        Contestant C=
            new Contestant("C", 1, 1,
                           new int[][] {{8,23}});
        //D disappears after 3 o'clock, never to be heard from again
        Contestant D=
            new Contestant("D", 1, 1,
                           new int[][] {{0,3}});

        Playground p=new Playground(5, 0.05, 0.60);
        p.add(A);
        p.add(B);
        p.add(C);
        p.add(D);
        p.run();
        //D is *gone*
        D.timing=new int[0][2];
        for (int x=0; x<30; x++) 
            p.run();
    }
}


    class Contestant {
        String name;
        double reliability, responseProbability;

        int timing[][], successes, failures;

        public Contestant(String name, double initialReliability,
                          double responseProbability,
                          int[][] timing) {
            this.name=name;
            reliability=initialReliability;
            this.timing=timing;
            this.responseProbability=responseProbability;
        }

        boolean picked() {
            return Math.random()<reliability;
        }

        boolean connect(float time) {
            for (int i=0; i<timing.length; i++) {
                if (time>=timing[i][0] &&
                    time<=timing[i][1] &&
                    Math.random()<responseProbability) {
                    successes++;
                    return true;
                }
            }
            failures++;
            return false;
        }

        public static String prettify(double fact) {
            return Double.toString(((double)((int)(fact*1000)))/1000);
        }

        public String toString() {
            return name+": "+prettify(reliability)+
                " r.f. -- "+successes+"\tsucessful connects, "+failures+
                "\tfailed connects";
        }
    }





-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.1 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE49KQWpXyM95IyRhURAlz2AJoDI/eKrrSx30SCUX8wBu4J/IOpagCfZcaG
cVfLHCPxBsFjg+l04KSuWCM=
=bCBB
-----END PGP SIGNATURE-----


_______________________________________________
Freenet-dev mailing list
Freenet-dev at lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/freenet-dev

Reply via email to