Beispiel #1
0
        public int main()
        {
            //double gama=0.01, double beta=0.50, double eta=0.50, double stgama=0.25, double rough=0.1, double alpha=0.50, double exploration=1.0, char * logfile="agent.xls", bool modeltype=1
            Agent A= new Agent(0.01, 0.50, 0.50,0.25,0.1,0.50,1.0, "A1.xls",true);
            EXPERIENCE E1, E2, E3;
            E1=new EXPERIENCE();
            E2=new EXPERIENCE();
            E3=new EXPERIENCE();

            E1.Experience	= 1;
            E1.TrusteeID	= 0;
            E2.Experience	= 0;
            E2.TrusteeID	= 1;
            E3.Experience	= -1;
            E3.TrusteeID	= 2;

            for (int i=0; i<5; i++) {
            A.updateTrust(E1);
            A.updateTrust(E2);
            A.updateTrust(E3);
            A.logTrust();
            }
            return 0;
        }
Beispiel #2
0
        public void mainMethod()
        {
            main myMain = new main();
            // stddev, mean

            Trustee T1 = new Trustee(0, 0.1, 1), T2 = new Trustee(1, 0.1, 0.5), T3 = new Trustee(2, 0.1, 0.1);

            //FILE * fptrgama, *fptr;
            StreamWriter fptrgama = new StreamWriter("Gama.xls"), fptr = new StreamWriter("Request.xls");

            //fptrgama = fopen ("Gama.xls", "w+");
            //fptr = fopen ("Request.xls", "w+");
            int requestA, requestB;
            double TExperienceA = 0.0, TExperienceB = 0.0, TExploration = 0.0, TEnvChange = 0.0, TDifference = 0.0;

            DateTime t = new DateTime();
            Random srand = new Random();

            //      Gama, Beta, Eta, StGama, Roh, Alpha, Exploration, LogFile
            Agent A = new Agent(0.1, 0.5, 1, 0.25, 0.25, 0.5, 1, "A1.xls", false);
            Agent B = new Agent(0.1, 0.5, 1, 0.25, 0.25, 0.5, 1, "B1.xls", true);

            EXPERIENCE[] E = new EXPERIENCE[3];
            EXPERIENCE eA = new EXPERIENCE();
            EXPERIENCE eB = new EXPERIENCE();

            E[0].Experience = 1;
            E[0].TrusteeID = 0;
            E[1].Experience = 0;
            E[1].TrusteeID = 1;
            E[2].Experience = -1;
            E[2].TrusteeID = 2;
            for (int i = 0; i < myMain.world.NO_OF_TIME_STEPS; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    RequestsOfA[i, j] = 0;
                    RequestsOfB[i, j] = 0;
                }
            }
            fptrgama.Write(string.Format("Alpha\tEEBDM\tMTBDM\tDifference\tEnvChange\tExploration"));

            //fprintf(fptrgama, "Alpha\tEEBDM\tMTBDM\tDifference\tEnvChange\tExploration");
            fptr.Write(string.Format("time\tA1\tB1\tA2\tB2\tA3\tB3\n"));
            //fprintf(fptr, "time\tA1\tB1\tA2\tB2\tA3\tB3\n");   

            int temp = 0;
            fptrgama.Flush();
#if MULTIPLE
for (double tt = 0.00;tt <= 1; tt=tt+0.01) {
        TExperienceA=0;
        TExperienceB=0;
        TExploration=0;
        TEnvChange=0;
        TDifference=0;
#endif

            for (int i = 0; i < myMain.world.NO_OF_SAMPLES; i++)
            {
                A.setAttribute(0.1, 0.5, 1, 0.25, 0.25, 0.5, 1);
                B.setAttribute(0.1, 0.5, 1, 0.25, 0.25, 0.5, 1);
                for (int j = 0; j < myMain.world.NO_OF_TIME_STEPS; j++)
                {
                    // start Case 1          
                    if (j == 0)
                    {
                        T1.setAttribute(0.1, 0.9);
                        T2.setAttribute(0.1, 0.1);
                        T3.setAttribute(0.1, 0.1);
                    }
                    if (j == 250)
                    {
                        T1.setAttribute(0.1, 0.5);
                        T2.setAttribute(0.1, 0.9);
                        T3.setAttribute(0.1, 0.9);
                    }
                    // end case 1


                    // start Case 2             
                    /*              if (j%25==0 && temp==0) {
                                        T1.setAttribute (0.1, 0.9);
                                        T2.setAttribute (0.1, 0.1);
                                        T3.setAttribute (0.1, 0.1);       
                                        temp=1;
                                        }
                                    else if (j%25==0 && temp==1) {
                                        T1.setAttribute (0.1, 0.1);
                                        T2.setAttribute (0.1, 0.9);
                                        T3.setAttribute (0.1, 0.9);        
                                        temp=0;
                                        }
                    // end case 2
                    */
                    // start Case 3
                    /*              if (j==0) {
                                        T1.setAttribute (0.1, 0.9);
                                        T2.setAttribute (0.1, 0.1);
                                        T3.setAttribute (0.1, 0.1);       
                                        }
                    // end case 3
                    */

                    requestA = (int)A.getRequest();
                    requestB = (int)B.getRequestMax();
                    //                printf("%ld\t", requestA);
                    //                printf("%ld\t", requestB);                
                    // start case 4                
                    /*
                                    if (requestA == 0)
                                       eA = T1.getExperienceFromUniformDistribution();
                                    else if (requestA == 1)
                                      eA = T2.getExperienceFromUniformDistribution();
                                    else
                                      eA = T3.getExperienceFromUniformDistribution();  
        
                                    if (requestB == 0)
                                      eB = T1.getExperienceFromUniformDistribution();
                                    else if (requestB == 1)
                                      eB = T2.getExperienceFromUniformDistribution();
                                    else
                                      eB = T3.getExperienceFromUniformDistribution();            
                    // end case 4
                    */
                    // start case 5
                    /*              if (j%250 == 0) {
                                        T1.setAttribute (0.1, random_uniform_distribution());
                                        T2.setAttribute (0.1, random_uniform_distribution());   
                                        T3.setAttribute (0.1, random_uniform_distribution());   
                                  }
                    */
                    // end case 5
                    //                printf("%lf\t", RequestsOfA [j][requestA]);
                    //                printf("%lf\t", RequestsOfA [j][requestA]);
                    RequestsOfA[j, requestA] = RequestsOfA[j, requestA] + 1;
                    RequestsOfB[j, requestB] = RequestsOfB[j, requestB] + 1;
                    //                printf("%lf\t", RequestsOfA [j][requestA]);
                    //                printf("%lf\t", RequestsOfA [j][requestA]);
                    //                getch();
                    if (requestA == 0)
                    {
                        eA = T1.getExperienceFromNormalDistribution();
                    }
                    else if (requestA == 1)
                    {
                        eA = T2.getExperienceFromNormalDistribution();

                    }
                    else
                    {
                        eA = T3.getExperienceFromNormalDistribution();

                    }

                    if (requestB == 0)
                    {
                        eB = T1.getExperienceFromNormalDistribution();

                    }
                    else if (requestB == 1)
                    {
                        eB = T2.getExperienceFromNormalDistribution();

                    }
                    else
                    {
                        eB = T3.getExperienceFromNormalDistribution();

                    }


                    A.updateTrust(eA);
                    B.updateTrust(eB);
                    A.flush_Filepointer();
                    B.flush_Filepointer();
                }
                TExperienceA += A.getTotalExperience() / myMain.world.NO_OF_TIME_STEPS;
                TExperienceB += B.getTotalExperience() / myMain.world.NO_OF_TIME_STEPS;
                TDifference += (A.getTotalExperience() - B.getTotalExperience()) / myMain.world.NO_OF_TIME_STEPS;
                TEnvChange += A.getTotalEnvChange() / myMain.world.NO_OF_TIME_STEPS;
                TExploration += A.getTotalExploration() / myMain.world.NO_OF_TIME_STEPS;
                //printf("%d\t", i);
                Console.Write(string.Format("{0}\t", i));
            }

#if MULTIPLE
    //    printf("%lf\t", t);
    Console.WriteLine("{0}\t",t);
        TExperienceA /=myMain.world.NO_OF_SAMPLES; 
        TExperienceB /=myMain.world.NO_OF_SAMPLES; 
        TDifference /=myMain.world.NO_OF_SAMPLES;
        TEnvChange /=myMain.world.NO_OF_SAMPLES;
        TExploration /=myMain.world.NO_OF_SAMPLES;
    fptrgama.Write("\n{0}\t{1}\t{2}\t{3}\t", t, TExperienceA, TExperienceB, TDifference)
        //fprintf(fptrgama, "\n%lf\t%lf\t%lf\t%lf\t", t, TExperienceA, TExperienceB, TDifference);
        fptrgama.Write( "{0}\t{1}", TEnvChange, TExploration);
        //fprintf(fptrgama, "%lf\t%lf", TEnvChange, TExploration);
   }
#endif
            for (int i = 0; i < myMain.world.NO_OF_TIME_STEPS; i++)
            {
                //      fprintf(fptr, "\n%d\t", i);
                fptr.WriteLine(string.Format("\n{0}\t", i));
                for (int j = 0; j < 3; j++)
                {
                    fptr.Write(string.Format("{0}\t{1}\t", RequestsOfA[i, j] / 1000.0, RequestsOfB[i, j] / 1000.0));

                    //fprintf(fptr, "%lf\t%lf\t", RequestsOfA [i,j]/1000.0, RequestsOfB [i,j]/1000.0);   
                    //      getch ();
                    /*                printf("%lf\t", RequestsOfA [i][j]);
                                    printf("%lf\t", RequestsOfB [i][j]);
                                    getch();
                    */
                }
            }


        }
Beispiel #3
0
        public void updateTrust(EXPERIENCE E)
        {
            int currentTrustee;
            double sigmaLongTermTrust = 0.0;
            double sigmaShortTermTrust = 0.0;
            double[] ProjectedLongTermTrust = new double[world.NO_OF_TRUSTEES];
            double[] ProjectedShortTermTrust = new double[world.NO_OF_TRUSTEES];

            time = time + world.TIME_SCALE;
            TotalExperience = TotalExperience + (E.Experience + 1) / 2;

            for (currentTrustee = 0; currentTrustee < world.NO_OF_TRUSTEES; currentTrustee++)
            {
                ProjectedLongTermTrust[currentTrustee] = (LongTermTrust[currentTrustee] + 1) / 2;
                ProjectedShortTermTrust[currentTrustee] = (ShortTermTrust[currentTrustee] + 1) / 2;
                sigmaLongTermTrust += ProjectedLongTermTrust[currentTrustee];
                sigmaShortTermTrust += ProjectedShortTermTrust[currentTrustee];
            }

            for (currentTrustee = 0; currentTrustee < world.NO_OF_TRUSTEES; currentTrustee++)
            {
                if (E.TrusteeID == currentTrustee)
                {
                    LongTermTrust[currentTrustee] += (Beta * (E.Experience + Eta * (ProjectedLongTermTrust[currentTrustee] - sigmaLongTermTrust / world.NO_OF_TRUSTEES) - LongTermTrust[currentTrustee]) - Gama * LongTermTrust[currentTrustee]) * (1 + LongTermTrust[currentTrustee]) * (1 - LongTermTrust[currentTrustee]) * world.TIME_SCALE;
                    ShortTermTrust[currentTrustee] += (Beta * (E.Experience + Eta * (ProjectedShortTermTrust[currentTrustee] - sigmaShortTermTrust / world.NO_OF_TRUSTEES) - ShortTermTrust[currentTrustee]) - StGama * ShortTermTrust[currentTrustee]) * (1 + ShortTermTrust[currentTrustee]) * (1 - ShortTermTrust[currentTrustee]) * world.TIME_SCALE;
                }
                else
                {
                    LongTermTrust[currentTrustee] += (Beta * (LongTermTrust[currentTrustee] + Eta * (ProjectedLongTermTrust[currentTrustee] - sigmaLongTermTrust / world.NO_OF_TRUSTEES) - LongTermTrust[currentTrustee]) - Gama * LongTermTrust[currentTrustee]) * (1 + LongTermTrust[currentTrustee]) * (1 - LongTermTrust[currentTrustee]) * world.TIME_SCALE;
                    ShortTermTrust[currentTrustee] += (Beta * (ShortTermTrust[currentTrustee] + Eta * (ProjectedShortTermTrust[currentTrustee] - sigmaShortTermTrust / world.NO_OF_TRUSTEES) - ShortTermTrust[currentTrustee]) - StGama * ShortTermTrust[currentTrustee]) * (1 + ShortTermTrust[currentTrustee]) * (1 - ShortTermTrust[currentTrustee]) * world.TIME_SCALE;
                }
            }
#if SINGLE
    logfptr.Write("\t{0}\t{1}\t",E.TrusteeID, E.Experience);
    for (currentTrustee = 0 ; currentTrustee < world.NO_OF_TRUSTEES; currentTrustee++) {
		logfptr.Write("{0}\t",LongTermTrust [currentTrustee]);
    }
#endif
        }