コード例 #1
0
        public static void computeUtility(string[] commandPieces, resultObject Result)
        {
            //usage computeutility AS d iteration
            if (commandPieces.Length < 4)
            {
                Console.WriteLine("computeutility [ASN] [dest] [iteration]");
                return;
            }

            UInt32 ASN, dest;
            Int32  iter;

            if (!UInt32.TryParse(commandPieces[1], out ASN) || !UInt32.TryParse(commandPieces[2], out dest) || !Int32.TryParse(commandPieces[3], out iter))
            {
                Console.WriteLine("bad params");
                return;
            }
            if (iter > Result.state.Count)
            {
                Console.WriteLine("iteration too large.");
                return;
            }
            bool[] iterState = Result.state[iter];
            foreach (var stub in Result.g.getStubs())
            {
                iterState[stub] = true;//turn on the stubs as in the sim
            }
            SimulatorLibrary.setUtilityComputation(UtilityComputationType.outgoing);
            GlobalState initial = SimulatorLibrary.initGlobalState(Result.g, Result.earlyAdopters, Result.weightedNodes, short.Parse(Result.k));
            Destination d       = new Destination(SimulatorLibrary.initMiniDestination(Result.g, dest, false));

            d.UpdatePaths(iterState);
            d.ComputeU(initial.W);
            Console.WriteLine("Utility for " + ASN + " in iteration: " + iter + " is " + d.U[ASN]);
            Worker w         = new Worker();
            int    afterFlip = w.ComputeUtility(d.BucketTable, d.Best, d.ChosenParent, d.SecP, iterState, ASN, d.L[ASN], d.BestRelation[ASN], initial.W);

            Console.WriteLine("Utility for " + ASN + " in iteration: " + iter + " if they flip is " + afterFlip);
        }
コード例 #2
0
        public void testSPInterface()
        {
            SimulatorLibrary.setHash(true);
            SimulatorLibrary.setUtilityComputation(UtilityComputationType.outgoing);
            Console.WriteLine("Welcome to the short paths testing interface: ");
            bool exitNow = false;


            while (!exitNow)
            {
                Console.Write(">>");
                string   command = Console.ReadLine().ToLower();
                string[] pieces  = command.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if (command.IndexOf("input") == 0)
                {
                    g = input(pieces);
                }
                else if (command.IndexOf("getpath") == 0)
                {
                    getpath(pieces);
                }
                else if (command.IndexOf("setstate") == 0)
                {
                    S = setstate(pieces);
                }
                else if (command.IndexOf("init") == 0)
                {
                    List <UInt32> ea = new List <uint>();
                    ea.Add(1239);
                    gs = SimulatorLibrary.initGlobalState(g, ea);
                }
                else if (command.IndexOf("iterate") == 0)
                {
                    List <MiniDestination> miniDs = new List <MiniDestination>();
                    foreach (var AS in g.GetAllNodes())
                    {
                        miniDs.Add(SimulatorLibrary.initMiniDestinationSP(g, AS.NodeNum, false));
                        Console.WriteLine("initialized AS " + AS.NodeNum);
                    }

                    List <Message> results = new List <Message>();
                    foreach (var mD in miniDs)
                    {
                        results.Add(SimulatorLibrary.ComputeOnDestination(mD, gs));
                        Console.WriteLine("computed on: " + mD.destination);
                    }
                    Console.WriteLine("updating global state.");
                    Int64[] Before = new Int64[Constants._numASNs];
                    Int64[] After  = new Int64[Constants._numASNs];


                    SimulatorLibrary.updateGlobalState(ref gs, results, (float)0, ref Before, ref After);
                    for (int i = 0; i < gs.S.Length; i++)
                    {
                        if (gs.S[i])
                        {
                            Console.WriteLine("AS " + i + " is on.");
                        }
                    }
                }
            }
        }