public bool CheckConnected()
        {
            try
            {
                Logger.Write("Research - " + ResearchName +
                             ". CHECK CONNECTED STARTED for network - " + NetworkID.ToString());

                bool result = false;
                Debug.Assert(networkGenerator.Container != null);
                networkAnalyzer.Container = networkGenerator.Container;
                object ccd = networkAnalyzer.CalculateOption(AnalyzeOption.ConnectedComponentDistribution);
                Debug.Assert(ccd is SortedDictionary <Double, Double>);
                SortedDictionary <Double, Double> r = ccd as SortedDictionary <Double, Double>;
                result = r.ContainsKey(networkGenerator.Container.Size);
                if (!result)
                {
                    UpdateStatus(NetworkStatus.StepCompleted);  // for analyze
                }

                Logger.Write("Research - " + ResearchName +
                             ". CHECK COMPLETED FINISHED for network - " + NetworkID.ToString());

                return(result);
            }
            catch (CoreException ex)
            {
                UpdateStatus(NetworkStatus.Failed);

                Logger.Write("Research - " + ResearchName +
                             "CHECK COMPLETED FAILED for network - " + NetworkID.ToString() +
                             ". Exception message: " + ex.Message);
                return(false);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Calculates specified analyze options values.
        /// </summary>
        public bool Analyze(bool visualMode = false)
        {
            if (networkAnalyzer.Container == null)
            {
                networkAnalyzer.Container = networkGenerator.Container;
            }

            try
            {
                CustomLogger.Write("Research - " + ResearchName +
                                   ". ANALYZE STARTED for network - " + NetworkID.ToString());

                NetworkResult.NetworkSize = networkAnalyzer.Container.Size;
                NetworkResult.EdgesCount  = networkAnalyzer.CalculateEdgesCount();

                Array existingOptions = Enum.GetValues(typeof(AnalyzeOption));
                foreach (AnalyzeOption opt in existingOptions)
                {
                    if (opt != AnalyzeOption.None && (AnalyzeOptions & opt) == opt)
                    {
                        NetworkResult.Result.Add(opt, networkAnalyzer.CalculateOption(opt, visualMode));

                        if ((opt == AnalyzeOption.Algorithm_1_By_All_Nodes ||
                             opt == AnalyzeOption.Algorithm_2_By_Active_Nodes_List ||
                             opt == AnalyzeOption.Algorithm_Final) && visualMode)
                        {
                            ActivesInformation = networkAnalyzer.ActivesInformation;
                        }

                        if ((opt == AnalyzeOption.Cycles3Evolution) && visualMode)
                        {
                            EvolutionInformation = networkAnalyzer.EvolutionInformation;
                        }

                        UpdateStatus(NetworkStatus.StepCompleted);

                        CustomLogger.Write("Research - " + ResearchName +
                                           ". CALCULATED analyze option: " + opt.ToString() +
                                           " for network - " + NetworkID.ToString());
                    }
                }

                SuccessfullyCompleted = true;

                CustomLogger.Write("Research - " + ResearchName +
                                   ". ANALYZE FINISHED for network - " + NetworkID.ToString());
            }
            catch (SystemException ex)
            {
                UpdateStatus(NetworkStatus.Failed);

                CustomLogger.Write("Research - " + ResearchName +
                                   ". ANALYZE FAILED for network - " + NetworkID.ToString() +
                                   ". Exception message: " + ex.Message);
                return(false);
            }

            return(true);
        }
Beispiel #3
0
        public void GetAll()
        {
            // create new device
            Update(ID, new { name = "_ut", network = new { name = "_ut_n" }, deviceClass = new { name = "_ut_dc", version = "1" } }, auth: Admin);
            RegisterForDeletion(ResourceUri + "/" + ID);

            // create another device
            var anotherDeviceId = Guid.NewGuid().ToString();

            Update(anotherDeviceId, new { name = "_ut2", network = new { name = "_ut_n_a" }, deviceClass = new { name = "_ut_dc_a", version = "1" } }, auth: Admin);
            var anotherDevice = Get(anotherDeviceId, auth: Admin);

            RegisterForDeletion("/network/" + (int)anotherDevice["network"]["id"]);
            RegisterForDeletion("/device/class/" + (int)anotherDevice["deviceClass"]["id"]);
            RegisterForDeletion(ResourceUri + "/" + anotherDeviceId);

            // admin: get device by name
            var devices = List(new Dictionary <string, string> {
                { "name", "_ut" }
            }, auth: Admin);

            Expect(devices.Count, Is.EqualTo(1));
            Expect(devices[0], Matches(new { id = ID }));

            // admin: get device by network
            devices = List(new Dictionary <string, string> {
                { "networkId", NetworkID.ToString() }
            }, auth: Admin);
            Expect(devices.Count, Is.EqualTo(1));
            Expect(devices[0], Matches(new { id = ID }));

            // admin: get device by device class
            devices = List(new Dictionary <string, string> {
                { "deviceClassId", DeviceClassID.ToString() }
            }, auth: Admin);
            Expect(devices.Count, Is.EqualTo(1));
            Expect(devices[0], Matches(new { id = ID }));

            // user: get all devices
            var user = CreateUser(1, NetworkID);

            devices = List(auth: user);
            Expect(devices.Count, Is.EqualTo(1));
            Expect(devices[0], Matches(new { id = ID }));

            // accesskey: get all devices
            var accessKey = CreateAccessKey(user, "GetDevice");

            devices = List(auth: accessKey);
            Expect(devices.Count, Is.EqualTo(1));
            Expect(devices[0], Matches(new { id = ID }));

            // accesskey: get all devices with no access
            accessKey = CreateAccessKey(user, "GetDevice", new[] { 0 });
            Expect(List(auth: accessKey).Count, Is.EqualTo(0));
            accessKey = CreateAccessKey(user, "GetDevice", null, new[] { Guid.NewGuid().ToString() });
            Expect(List(auth: accessKey).Count, Is.EqualTo(0));
        }
        /// <summary>
        /// Traces the adjacency matrix of generated network to file.
        /// </summary>
        public bool Trace(string tracingPath)
        {
            try
            {
                Logger.Write("Research - " + ResearchName +
                             ". TRACING STARTED for network - " + NetworkID.ToString());

                if (TracingIsNotSupported())
                {
                    return(true);
                }

                if (RandNetSettings.TracingType == TracingType.Matrix)
                {
                    MatrixInfoToWrite matrixInfo = new MatrixInfoToWrite();
                    matrixInfo.Matrix = networkGenerator.Container.GetMatrix();
                    if (networkGenerator.Container is AbstractHierarchicContainer)
                    {
                        matrixInfo.Branches = (networkGenerator.Container as AbstractHierarchicContainer).GetBranches();
                    }
                    matrixInfo.ActiveStates = (networkGenerator.Container as AbstractNetworkContainer).GetActiveStatuses();

                    FileManager.Write(matrixInfo, tracingPath);
                }
                else if (RandNetSettings.TracingType == TracingType.Neighbourship)
                {
                    NeighbourshipInfoToWrite neighbourshipInfo = new NeighbourshipInfoToWrite();
                    neighbourshipInfo.Neighbourship = networkGenerator.Container.GetNeighbourship();
                    if (networkGenerator.Container is AbstractHierarchicContainer)
                    {
                        neighbourshipInfo.Branches = (networkGenerator.Container as AbstractHierarchicContainer).GetBranches();
                    }
                    neighbourshipInfo.ActiveStates = (networkGenerator.Container as AbstractNetworkContainer).GetActiveStatuses();

                    FileManager.Write(neighbourshipInfo, tracingPath);
                }

                UpdateStatus(NetworkStatus.StepCompleted);

                Logger.Write("Research - " + ResearchName +
                             ". TRACING FINISHED for network - " + NetworkID.ToString());
            }
            catch (CoreException ex)
            {
                UpdateStatus(NetworkStatus.Failed);

                Logger.Write("Research - " + ResearchName +
                             "TRACING FAILED for network - " + NetworkID.ToString() +
                             ". Exception message: " + ex.Message);
                return(false);
            }

            return(true);
        }
Beispiel #5
0
        /// <summary>
        /// Generates random network from generation parameters.
        /// </summary>
        public bool Generate(bool visualMode = false)
        {
            try
            {
                CustomLogger.Write("Research - " + ResearchName +
                                   ". GENERATION STARTED for network - " + NetworkID.ToString());

                if (GenerationType == GenerationType.Static)
                {
                    Debug.Assert(GenerationParameterValues.ContainsKey(GenerationParameter.AdjacencyMatrix));
                    MatrixPath fp = (MatrixPath)GenerationParameterValues[GenerationParameter.AdjacencyMatrix];
                    Debug.Assert(fp.Path != null && fp.Path != "");
                    NetworkInfoToRead ni = FileManager.Read(fp.Path, fp.Size);
                    networkGenerator.StaticGeneration(ni);

                    CustomLogger.Write("Research - " + ResearchName +
                                       ". Static GENERATION FINISHED for network - " + NetworkID.ToString());
                }
                else
                {
                    Debug.Assert(!GenerationParameterValues.ContainsKey(GenerationParameter.AdjacencyMatrix));
                    networkGenerator.RandomGeneration(GenerationParameterValues, visualMode);
                    if (ResearchType == ResearchType.Activation)
                    {
                        Debug.Assert(ResearchParameterValues.ContainsKey(ResearchParameter.InitialActivationProbability));
                        Double IP = Double.Parse(ResearchParameterValues[ResearchParameter.InitialActivationProbability].ToString(),
                                                 CultureInfo.InvariantCulture);
                        (networkGenerator.Container as AbstractNetworkContainer).RandomActivating(IP);
                    }
                    if (visualMode)
                    {
                        Debug.Assert(networkGenerator.GenerationSteps != null);
                        GenerationSteps = networkGenerator.GenerationSteps;
                        Branches        = networkGenerator.Container.GetBranches();
                    }

                    CustomLogger.Write("Research - " + ResearchName +
                                       ". Random GENERATION FINISHED for network - " + NetworkID.ToString());
                }

                UpdateStatus(NetworkStatus.StepCompleted);
            }
            catch (CoreException ex)
            {
                UpdateStatus(NetworkStatus.Failed);

                CustomLogger.Write("Research - " + ResearchName +
                                   "GENERATION FAILED for network - " + NetworkID.ToString() +
                                   ". Exception message: " + ex.Message);
                return(false);
            }

            return(true);
        }
        public virtual JSONNode GetJson()
        {
            var kingdomNode = new JSONNode();

            kingdomNode.SetAs("KingdomType", KingdomType);
            kingdomNode.SetAs("NpcID", NpcID);
            kingdomNode.SetAs("Name", Name);
            kingdomNode.SetAs("Origin", (JSONNode)Origin);
            kingdomNode.SetAs("NetworkID", NetworkID.ToString());
            return(kingdomNode);
        }
        /// <summary>
        /// Calculates specified analyze options values.
        /// </summary>
        public bool Analyze()
        {
            if (networkAnalyzer.Container == null)
            {
                networkAnalyzer.Container = networkGenerator.Container;
            }

            try
            {
                Logger.Write("Research - " + ResearchName +
                             ". ANALYZE STARTED for network - " + NetworkID.ToString());

                NetworkResult.NetworkSize = networkAnalyzer.Container.Size;
                NetworkResult.EdgesCount  = networkAnalyzer.CalculateEdgesCount();

                Array existingOptions = Enum.GetValues(typeof(AnalyzeOption));
                foreach (AnalyzeOption opt in existingOptions)
                {
                    if (opt != AnalyzeOption.None && (AnalyzeOptions & opt) == opt)
                    {
                        NetworkResult.Result.Add(opt, networkAnalyzer.CalculateOption(opt));
                        UpdateStatus(NetworkStatus.StepCompleted);

                        Logger.Write("Research - " + ResearchName +
                                     ". CALCULATED analyze option: " + opt.ToString() +
                                     " for network - " + NetworkID.ToString());
                    }
                }

                SuccessfullyCompleted = true;

                Logger.Write("Research - " + ResearchName +
                             ". ANALYZE FINISHED for network - " + NetworkID.ToString());
            }
            catch (SystemException ex)
            {
                UpdateStatus(NetworkStatus.Failed);

                Logger.Write("Research - " + ResearchName +
                             "ANALYZE FAILED for network - " + NetworkID.ToString() +
                             ". Exception message: " + ex.Message);
                return(false);
            }

            return(true);
        }
Beispiel #8
0
        private bool TracingIsNotSupported()
        {
            bool support = networkGenerator.Container.Size > 30000;

            //if (networkGenerator.Container is AbstractHierarchicContainer)
            //{
            //    networkAnalyzer.Container = networkGenerator.Container;
            //    support = (networkAnalyzer.CalculateEdgesCount() > 10000000);
            //}
            //else support = (networkGenerator.Container.Size > 30000);

            if (support)
            {
                UpdateStatus(NetworkStatus.StepCompleted);

                CustomLogger.Write("Research - " + ResearchName +
                                   ". TRACING is SKIPPED for network - " + NetworkID.ToString());
            }

            return(support);
        }
Beispiel #9
0
 private string GetRoomNumberFromNetworkId(NetworkID networkID)
 {
     return((System.Convert.ToInt64(networkID.ToString()) % 10000).ToString());
 }
    /// <summary>
    /// Instantiates a prefab and assigns a network ID to it.
    /// This is replicated across all peers, and is buffered for any new players.
    /// To destroy these objects, you should use the "NetworkDestroy" function.
    /// </summary>
    /// <param name="pos">Position.</param>
    /// <param name="rot">Rot.</param>
    public GameObject NetworkInstantiate(NetworkPrefab prefab, Vector3 pos, Quaternion rot, bool sendToLocalClient)
    {
        if (NetworkCore.isServer)
        {
            if (prefab == null)
            {
                Debug.LogError("NetworkInstantiate called with no prefab. Object not created");
                return(null);
            }
            GameObject  newObj = Instantiate(prefab.serverPrefab, pos, rot);
            NetObjectID idComp = newObj.GetComponent <NetObjectID>();
            NetworkID   newID  = GetNextID(idComp);
            idComp.SetNetID(newID);
            NetWriter writer = StartNetworkMessage("cl_NetworkInstantiate", thisNetworkID);
            writer.WriteInt(prefab.id);
            writer.WriteVector3(pos);
            writer.WriteVector3(rot.eulerAngles);
            newID.WriteBytes(writer);
            BufferedMessage msg = null;
            if (sendToLocalClient)
            {
                msg = SendMessageToAllClients(writer, NetworkCore.AllCostMsg, true);
            }
            else
            {
                msg = SendMessageToOtherClients(writer, NetworkCore.AllCostMsg, true);
            }

            if (msg == null)
            {
                Debug.Log("Failed to successfully send Instantiation message. Unregistering Network ID: " + newID.ToString());
                FreeNetworkID(idComp);
                return(newObj);
            }
            idComp.AddBufferedMessage(msg);
            newObj.BroadcastMessage("OnNewNetworkSceneLoaded");
            return(newObj);
        }
        return(null);
    }