protected override Parameters AddParameters(INetworkData ndata)
        {
            Boolean undirected = CheckDataUndirected(ndata);
            Boolean connected  = CheckDataConnected(ndata);
            var     valuesList = new List <String>()
            {
                "Network \t Density", "Network \t Average node connectivity", "Network \t Node connectivity", "Network \t Edge connectivity", "Network \t Diameter", "Network \t Radius", "Node \t Degree", "Node \t Out-degree", "Node \t Degree centrality", "Node \t In-degree centrality", "Node \t Out-degree centrality", "Node \t Closeness centrality", "Node \t Betweenness centrality", "Node \t Average neighbor degree", "Node \t Clustering coefficient", "Edge \t Betweenness centrality"
            };

            string[]   values        = UpdateParameterPropertyValues(valuesList, undirected, connected);
            string[]   directedOrNot = { undirected ? "Undirected" : "Directed" };
            Parameters parameters    = new Parameters();

            parameters.AddParameterGroup(new Parameter[] { new MultiChoiceParam("Properties", new int[0] {
                })
                                                           {
                                                               Values = values,
                                                               Help   = "Please select here the properties that should be calculated."
                                                           } }, "", false);
            parameters.AddParameterGroup(new Parameter[] { new SingleChoiceParam("Graph type")
                                                           {
                                                               Values  = directedOrNot,
                                                               Visible = false,
                                                           } }, "", false);
            return(parameters);
        }
 public bool RuntimeValidation(ref string error)
 {
     if (Parent == null)
     {
         error = "The parent model was never set!";
         return(false);
     }
     if (AutoNetworkName != null && AutoNetworkName != String.Empty)
     {
         INetworkData autoData = null;
         if (Parent.NetworkData == null)
         {
             error = "There was no Network Data in the Model System to load from!";
             return(false);
         }
         for (int i = 0; i < Parent.NetworkData.Count; i++)
         {
             if (Parent.NetworkData[i].NetworkType == AutoNetworkName)
             {
                 autoData = Parent.NetworkData[i];
                 break;
             }
         }
         if (autoData == null)
         {
             error = "There was no auto network!";
             return(false);
         }
     }
     return(true);
 }
Exemple #3
0
        /// <summary>
        /// React to network data from the server based on command
        /// </summary>
        /// <param name="command">Byte that represents command</param>
        /// <param name="data">Actual network data itself</param>
        private void HandleCommand(byte command, INetworkData data)
        {
            DataReceived?.Invoke(data);
            switch (command)
            {
            case Command.None:
                _logger.Log("No command was received.");
                break;

            case Command.Ping:
            case Command.Position:
            case Command.Rotation:
            case Command.Spawn:
            case Command.Scale:
            case Command.Connect:
            case Command.Disconnect:
            case Command.Register:
            case Command.Unregister:
                break;

            default:
                _logger.Log("Unrecognized command.");
                break;
            }
        }
        public static void Read(INetworkData ndata, string outFolder, ProcessInfo processInfo)
        {
            ReadMatrixDataInto(ndata, Path.Combine(outFolder, "networks.txt"), processInfo);
            foreach (var netAttr in ndata.GetStringColumn("guid").Zip(ndata.GetStringColumn("name"), (guid, name) => new { guid, name }))
            {
                var guid      = Guid.Parse(netAttr.guid);
                var nodeTable = PerseusFactory.CreateDataWithAnnotationColumns();
                var edgeTable = PerseusFactory.CreateDataWithAnnotationColumns();
                ReadMatrixDataInto(nodeTable, Path.Combine(outFolder, $"{guid}_nodes.txt"), processInfo);
                ReadMatrixDataInto(edgeTable, Path.Combine(outFolder, $"{guid}_edges.txt"), processInfo);
                var graph      = new Graph();
                var nodeIndex  = new Dictionary <INode, int>();
                var nameToNode = new Dictionary <string, INode>();
                var nodeColumn = nodeTable.GetStringColumn("node");

                for (int row = 0; row < nodeTable.RowCount; row++)
                {
                    var node = graph.AddNode();
                    nodeIndex[node]             = row;
                    nameToNode[nodeColumn[row]] = node;
                }
                var sourceColumn = edgeTable.GetStringColumn("source");
                var targetColumn = edgeTable.GetStringColumn("target");
                var edgeIndex    = new Dictionary <IEdge, int>();
                for (int row = 0; row < edgeTable.RowCount; row++)
                {
                    var source = nameToNode[sourceColumn[row]];
                    var target = nameToNode[targetColumn[row]];
                    var edge   = graph.AddEdge(source, target);
                    edgeIndex[edge] = row;
                }
                ndata.AddNetworks(new NetworkInfo(graph, nodeTable, nodeIndex, edgeTable, edgeIndex, netAttr.name, guid));
            }
            ReadMatrixDataInto(ndata, Path.Combine(outFolder, "networks.txt"), processInfo);
        }
Exemple #5
0
        public void ProcessData(IMatrixData inData, INetworkData outData, Parameters param, ref IData[] supplData, ProcessInfo processInfo)
        {
            var remoteExe = param.GetParam <string>(InterpreterLabel).Value;
            var inFile    = Path.GetTempFileName();

            PerseusUtils.WriteMatrixToFile(inData, inFile, false);
            var paramFile = Path.GetTempFileName();

            param.ToFile(paramFile);
            var outFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            if (!TryGetCodeFile(param, out string codeFile))
            {
                processInfo.ErrString = $"Code file '{codeFile}' was not found";
                return;
            }
            var suppFiles = SupplDataTypes.Select(Utils.CreateTemporaryPath).ToArray();
            var args      = $"{codeFile} {paramFile} {inFile} {outFolder} {string.Join(" ", suppFiles)}";

            Debug.WriteLine($"executing > {remoteExe} {args}");
            if (Utils.RunProcess(remoteExe, args, processInfo.Status, out string processInfoErrString) != 0)
            {
                processInfo.ErrString = processInfoErrString;
                return;
            }
            ;
            FolderFormat.Read(outData, outFolder, processInfo);
            supplData = Utils.ReadSupplementaryData(suppFiles, SupplDataTypes, processInfo);
        }
        public void RunNetworkAssignment()
        {
            INetworkData autoData = GetAutoNetwork();

            if (this.RunEMME)
            {
                do
                {
                    // If we don't have a working controller try to re-initialize it, and re-startup the system
                    if (this.Controller == null)
                    {
                        // Pick which controller to use
                        InitializeController();
                        ExecuteStartupMacro();
                    }
                    // Now that the system has been initialized run the macro
                    if (!Controller.Run(this.EmmeAssignmentMacro, this.EmmeParameters))
                    {
                        // if we failed to run the macro, kill the controller and try again
                        this.Controller.Close();
                        this.Controller = null;
                        continue;
                    }
                    // if we have gotten here then we successfully ran, and can continue on
                    break;
                } while (true);
            }
        }
Exemple #7
0
 public bool RuntimeValidation(ref string error)
 {
     AssignRequiredVehicle();
     if (RequiresVehicle == null)
     {
         error = $"In {Name} we were unable to find a vehicle type with the name {VehicleTypeName}!";
         return(false);
     }
     foreach (var network in Root.NetworkData)
     {
         if (network.NetworkType == AutoNetworkName)
         {
             AutoNetwork = network;
         }
         else if (network.NetworkType == TransitNetworkName)
         {
             TransitNetwork = network as ITripComponentData;
         }
     }
     if (AutoNetwork == null)
     {
         error = "In '" + Name + "' we were unable to find an auto network called '" + AutoNetworkName + "'";
         return(false);
     }
     if (TransitNetwork == null)
     {
         error = "In '" + Name + "' we were unable to find a transit network called '" + TransitNetworkName + "'";
         return(false);
     }
     return(true);
 }
            private float ComputeUtility(INetworkData autoNetwork, int originIndex, int destinationIndex)
            {
                float aivtt, cost;

                autoNetwork.GetAllData(originIndex, destinationIndex, StartTime, out aivtt, out cost);
                return(AIVTT * aivtt + AutoCost * cost);
            }
        private INetworkData GetAutoNetwork()
        {
            INetworkData autoData = null;

            if (!String.IsNullOrWhiteSpace(this.AutoNetworkName))
            {
                try
                {
                    if (this.Parent.NetworkData != null)
                    {
                        for (int i = 0; i < this.Parent.NetworkData.Count; i++)
                        {
                            if (this.Parent.NetworkData[i].NetworkType == this.AutoNetworkName)
                            {
                                autoData = this.Parent.NetworkData[i];
                                break;
                            }
                        }
                    }
                }
                catch
                {
                }
            }
            return(autoData);
        }
 public bool RuntimeValidation(ref string error)
 {
     //search through the networks and load in the data based on their names
     foreach (var network in Root.NetworkData)
     {
         if (network.NetworkType == TransitNetworkString)
         {
             TransitNetwork = network as ITripComponentData;
         }
         if (network.NetworkType == AutoNetworkString)
         {
             AutoNetwork = network;
         }
     }
     // check to make sure that both networks were loaded in, if not report an error
     if (AutoNetwork == null)
     {
         error = "In '" + Name + "' a auto network named '" + AutoNetworkString + "' could not be found.";
         return(false);
     }
     if (TransitNetwork == null)
     {
         error = "In '" + Name + "' a transit network named '" + TransitNetworkString + "' could not be found.";
         return(false);
     }
     return(true);
 }
        public virtual void Refresh()
        {
            try {
                //Log.Debug("UISliderBase.Refresh() was called\n" /*+ Environment.StackTrace*/);
                INetworkData data = Root.GetData();
                RefreshValues();

                // RefreshValues sets and then unsets Refreshing. therefore this must be called after RefreshValues.
                Refreshing = true;

                if (isEnabled && data is NodeData nodeData)
                {
                    RefreshNode(nodeData);
                }

                parent.isVisible = isEnabled;
                parent.Invalidate();
                //Invalidate(); // TODO is this redundant?
                //thumbObject.Invalidate();
                //SlicedSprite.Invalidate();
                //Log.Debug($"slider.Refresh: node:{data.NodeID} isEnabled={isEnabled}\n" + Environment.StackTrace);
            }
            finally {
                Refreshing = false;
            }
        }
Exemple #12
0
        /// <summary>
        /// This is called before the start method as a way to pre-check that all of the parameters that are selected
        /// are in fact valid for this module.
        /// </summary>
        /// <param name="error">A string that should be assigned a detailed error</param>
        /// <returns>If the validation was successful or if there was a problem</returns>
        public bool RuntimeValidation(ref string error)
        {
            if (TashaRuntime == null)
            {
                error = "The Root Model System for the taxi mode was never loaded!";
                return(false);
            }
            if (TashaRuntime.NetworkData == null)
            {
                error = "There was no network data in this model system to load from!";
                return(false);
            }
            bool found = false;

            foreach (var data in TashaRuntime.NetworkData)
            {
                if (data.NetworkType == AutoNetworkName)
                {
                    found = true;
                    Data  = data;
                    break;
                }
            }
            if (!found)
            {
                error = "We could not find any data named " + AutoNetworkName + " to load as the auto network data for the Taxi mode!";
                return(false);
            }
            return(true);
        }
Exemple #13
0
        public bool RuntimeValidation(ref string error)
        {
            if (String.IsNullOrWhiteSpace(this.ModeName))
            {
                error = "All modes require a mode name!";
                return(false);
            }
            bool found = false;
            IList <INetworkData> networks;

            networks = this.Root.NetworkData;
            foreach (var network in networks)
            {
                if (network.NetworkType == this.NetworkType)
                {
                    this.NetworkData = network as INetworkData;
                    if (this.NetworkData == null)
                    {
                        error = "The network data \"" + this.NetworkType + "\" does not support the ITransitNetworkData interface.  Please use a module that supports this!";
                        return(false);
                    }
                    found = true;
                    break;
                }
            }
            if (!found)
            {
                error = "We were unable to find the network data with the name \"" + this.NetworkType + "\" in this Model System!";
                return(false);
            }
            TestMaxTime = (this.MaxTime != Time.Zero);
            return(true);
        }
Exemple #14
0
        public void LoadData(INetworkData ndata, Parameters param, ref IData[] supplData, ProcessInfo processInfo)
        {
            var remoteExe = GetExectuable(param);

            if (string.IsNullOrWhiteSpace(remoteExe))
            {
                processInfo.ErrString = Resources.RemoteExeNotSpecified;
            }
            var outFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            if (!TryGetCodeFile(param, out string codeFile))
            {
                processInfo.ErrString = $"Code file '{codeFile}' was not found";
                return;
            }
            var suppFiles            = SupplDataTypes.Select(Utils.CreateTemporaryPath).ToArray();
            var commandLineArguments = GetCommandLineArguments(param);
            var args = $"{codeFile} {commandLineArguments} {outFolder} {string.Join(" ", suppFiles)}";

            Debug.WriteLine($"executing > {remoteExe} {args}");
            if (Utils.RunProcess(remoteExe, args, processInfo.Status, out string processInfoErrString) != 0)
            {
                processInfo.ErrString = processInfoErrString;
                return;
            }
            FolderFormat.Read(ndata, outFolder, processInfo);
            supplData = Utils.ReadSupplementaryData(suppFiles, SupplDataTypes, processInfo);
        }
Exemple #15
0
        protected override CustomUILabel AddItem(INetworkData data)
        {
            var item = base.AddItem(data);

            item.autoSize          = false;
            item.width             = ItemWidth;
            item.height            = 18f;
            item.textScale         = 0.65f;
            item.textAlignment     = UIHorizontalAlignment.Center;
            item.verticalAlignment = UIVerticalAlignment.Middle;
            item.padding.top       = 3;
            item.atlas             = TextureHelper.InGameAtlas;
            item.backgroundSprite  = "ButtonWhite";

            if (data is NodeData)
            {
                item.text = NodeController.Localize.Options_All;
            }
            if (data is SegmentEndData endData)
            {
                item.color = endData.Color;
                item.text  = $"#{endData.Id}";
            }

            return(item);
        }
Exemple #16
0
        public bool RuntimeValidation(ref string error)
        {
            foreach (var network in this.Root.NetworkData)
            {
                if (network.Name == this.AccessModeName)
                {
                    this.First = network;
                }

                if (network.Name == this.PrimaryModeName)
                {
                    var temp = network as ITripComponentData;
                    this.Second = temp == null ? this.Second : temp;
                }
            }
            if (this.First == null)
            {
                error = "In '" + this.Name + "' the name of the access network data type was not found!";
                return(false);
            }
            else if (this.Second == null)
            {
                error = "In '" + this.Name + "' the name of the primary network data type was not found or does not contain trip component data!";
                return(false);
            }
            return(true);
        }
Exemple #17
0
 public bool RuntimeValidation(ref string error)
 {
     foreach (var network in Root.NetworkData)
     {
         if (network.NetworkType == AutoNetworkName)
         {
             AutoNetwork = network;
         }
         else if (network.NetworkType == TransitNetworkName)
         {
             TransitNetwork = network as ITripComponentData;
         }
     }
     if (AutoNetwork == null)
     {
         error = "In '" + Name + "' we were unable to find an auto network called '" + AutoNetworkName + "'";
         return(false);
     }
     if (TransitNetwork == null)
     {
         error = "In '" + Name + "' we were unable to find a transit network called '" + TransitNetworkName + "'";
         return(false);
     }
     return(true);
 }
        private void DrawNetworkNodes(INetworkData networkData)
        {
            foreach (var node in networkData.Network.Nodes)
            {
                var ellipse = new Ellipse
                {
                    Stroke              = Brushes.Blue,
                    StrokeThickness     = 2.0,
                    Fill                = Brushes.CornflowerBlue,
                    Width               = 20,
                    Height              = 20,
                    Margin              = new Thickness(node.PositionX - 10, node.PositionY - 10, 0, 0),
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment   = VerticalAlignment.Top
                };
                CanvasResult.Children.Add(ellipse);

                var value = new TextBlock
                {
                    Text   = $"{node.Value:F0}",
                    Margin = new Thickness(node.PositionX - 25, node.PositionY - 25, 0, 0),
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment   = VerticalAlignment.Top
                };
                CanvasResult.Children.Add(value);
            }
        }
Exemple #19
0
        private bool FindAutoData(ref string error)
        {
            IList <INetworkData> networks;

            networks = this.Root.NetworkData;
            if (String.IsNullOrWhiteSpace(this.NetworkType))
            {
                error = "There was no network type selected for the " + (String.IsNullOrWhiteSpace(this.ModeName) ? "Auto" : this.ModeName) + " mode!";
                return(false);
            }
            if (networks == null)
            {
                error = "There was no Auto Network loaded for the Auto Mode!";
                return(false);
            }
            bool found = false;

            foreach (var network in networks)
            {
                if (network.NetworkType == this.NetworkType)
                {
                    this.AutoData = network;
                    found         = true;
                    break;
                }
            }
            if (!found)
            {
                error = "We were unable to find the network data with the name \"" + this.NetworkType + "\" in this Model System!";
                return(false);
            }
            return(true);
        }
Exemple #20
0
 public object this[string key, int peerId]
 {
     get {
         if (!GameController.Instance.IsHost)
         {
             throw new InvalidOperationException("Invalid operation as client.");
         }
         if (!NetworkUtils.GetNetworkDataFromClient(networkSync.ObjectID, peerId).ContainsKey(key))
         {
             return(null);
         }
         return(NetworkUtils.GetNetworkDataFromClient(networkSync.ObjectID, peerId)[key]);
     }
     set {
         if (!GameController.Instance.IsHost)
         {
             throw new InvalidOperationException("Invalid operation as client.");
         }
         INetworkData data = value as INetworkData;
         if (data != null)
         {
             data.Type = data.GetType().Name;
         }
         NetworkUtils.GetNetworkDataFromClient(networkSync.ObjectID, peerId)[key] = value;
     }
 }
Exemple #21
0
        /// <summary>
        /// This is called before the start method as a way to pre-check that all of the parameters that are selected
        /// are in fact valid for this module.
        /// </summary>
        /// <param name="error">A string that should be assigned a detailed error</param>
        /// <returns>If the validation was successful or if there was a problem</returns>
        public bool RuntimeValidation(ref string error)
        {
            var networks = TashaRuntime.NetworkData;

            if (networks == null)
            {
                error = "There was no Auto Network loaded for the Passenger Mode!";
                return(false);
            }
            bool found = false;

            foreach (var network in networks)
            {
                if (network.NetworkType == NetworkType)
                {
                    AutoData = network;
                    found    = true;
                    break;
                }
            }
            if (!found)
            {
                error = "We were unable to find the network data with the name \"Auto\" in this Model System!";
                return(false);
            }
            return(true);
        }
Exemple #22
0
 private List <INetworkData> DeserializeData(byte[] serializedData, int totalDataLength)
 {
     try
     {
         List <INetworkData> dataList = new List <INetworkData>();
         int bytesRead = 0;
         _logger.Log($"Deserializing data of total length: {totalDataLength}");
         do
         {
             _logger.Log($"Bytes read: {bytesRead}");
             INetworkData data = MessagePackSerializer.Deserialize <INetworkData>(serializedData, out var curBytesRead);
             dataList.Add(data);
             _logger.Log($"DataList length: {dataList.Count}");
             bytesRead     += curBytesRead;
             serializedData = serializedData.Skip(curBytesRead).ToArray();
             _logger.Log($"Left to deserialize: {totalDataLength - bytesRead}");
         } while (bytesRead < totalDataLength);
         return(dataList);
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
         return(null);
     }
     // BinaryFormatter formatter = new BinaryFormatter();
     // INetworkData data;
     // using (var stream = new MemoryStream(serializedData))
     // {
     //     data = (INetworkData)formatter.Deserialize(stream);
     // }
     // return data;
 }
Exemple #23
0
        public bool RuntimeValidation(ref string error)
        {
            if (String.IsNullOrWhiteSpace(this.ModeName))
            {
                error = "In module '" + this.Name + "', please add in a 'Mode Name' for your nested choice!";
                return(false);
            }
            if (this.Correlation > 1 || this.Correlation < 0)
            {
                error = "Correlation must be between 0 and 1 for " + this.ModeName + "!";
                return(false);
            }
            if (MaxAccessStations <= 0)
            {
                error = "The number of feasible access stations must be greater than 0!";
                return(false);
            }
            foreach (var network in this.Root.NetworkData)
            {
                if (network.NetworkType == this.AccessModeName)
                {
                    this.First = network;
                }

                if (network.NetworkType == this.PrimaryModeName)
                {
                    var temp = network as ITripComponentData;
                    this.Second = temp == null ? this.Second : temp;
                }

                if (network.NetworkType == this.EgressNetworkName)
                {
                    var temp = network as ITripComponentData;
                    this.Third = temp == null ? this.Third : temp;
                }

                if (network.NetworkType == this.AlternativePrimaryModeName)
                {
                    this.FirstAlternative = network;
                }
            }
            if (this.First == null)
            {
                error = "In '" + this.Name + "' the name of the access network data type was not found!";
                return(false);
            }
            else if (this.Second == null)
            {
                error = "In '" + this.Name + "' the name of the primary network data type was not found or does not contain trip component data!";
                return(false);
            }
            else if (this.Third == null && this.ComputeEgressStation)
            {
                error = "In '" + this.Name + "' the name of the egress network data type was not found or does not contain trip component data!";
                return(false);
            }
            return(true);
        }
            private void CalculateUtilities(RangeSet stationRanges, RangeSet spatialZones, float[] capacity, int[] closestStation)
            {
                INetworkData       autoNetwork    = GetNetwork(AutoNetworkName);
                ITripComponentData transitNetwork = GetNetwork(TransitNetworkName) as ITripComponentData;

                EnsureNetworks(autoNetwork, transitNetwork);
                var zoneArray = Root.ZoneSystem.ZoneArray;

                IZone[] zones              = zoneArray.GetFlatData();
                int[]   stationZones       = GetStationZones(stationRanges, capacity, zones);
                var     flatCapacityFactor = CapacityFactor.GetFlatData();

                if (AutoFromOriginToAccessStation == null || TransitFromAccessStationToDestination.Length != stationZones.Length * zones.Length)
                {
                    TransitFromAccessStationToDestination = new float[stationZones.Length * zones.Length];
                    AutoFromOriginToAccessStation         = new float[stationZones.Length * zones.Length];
                    TransitFromDestinationToAccessStation = new float[stationZones.Length * zones.Length];
                    AutoFromAccessStationToDestination    = new float[stationZones.Length * zones.Length];
                }
                // compute the toAccess utilities
                Parallel.For(0, zones.Length, (int originIndex) =>
                {
                    var zoneNumber = zones[originIndex].ZoneNumber;
                    if (spatialZones.Contains(zoneNumber))
                    {
                        for (int i = 0; i < stationZones.Length; i++)
                        {
                            var accessIndex = stationZones[i];
                            var factor      = (float)Math.Pow(flatCapacityFactor[accessIndex], CapacityFactorExp);
                            // calculate access' to access station this will include more factors
                            AutoFromOriginToAccessStation[originIndex * stationZones.Length + i] = (float)Math.Exp(ComputeUtility(autoNetwork, originIndex, accessIndex)
                                                                                                                   + (Capacity * capacity[accessIndex]
                                                                                                                      + ParkingCost * zones[accessIndex].ParkingCost
                                                                                                                      + (closestStation[originIndex] == accessIndex ? ClosestStationFactor : 0))) * factor;
                            // calculate egress' from access station
                            AutoFromAccessStationToDestination[originIndex * stationZones.Length + i] = (float)Math.Exp(ComputeUtility(autoNetwork, accessIndex, originIndex)) * factor;
                        }
                    }
                });

                // compute the toDesinstination utilities
                Parallel.For(0, zones.Length, (int destIndex) =>
                {
                    var zoneNumber = zones[destIndex].ZoneNumber;
                    if (spatialZones.Contains(zoneNumber))
                    {
                        for (int i = 0; i < stationZones.Length; i++)
                        {
                            var accessIndex = stationZones[i];
                            var factor      = (float)Math.Pow(flatCapacityFactor[accessIndex], CapacityFactorExp);
                            // calculate access' to destination
                            TransitFromAccessStationToDestination[destIndex * stationZones.Length + i] = (float)Math.Exp(ComputeUtility(transitNetwork, accessIndex, destIndex)) * factor;
                            // calculate egress' to access station
                            TransitFromDestinationToAccessStation[destIndex * stationZones.Length + i] = (float)Math.Exp(ComputeUtility(transitNetwork, destIndex, accessIndex)) * factor;
                        }
                    }
                });
            }
 public Boolean CheckDataUndirected(INetworkData ndata)
 {
     foreach (var network in ndata)
     {
         if (!CheckNetworkUndirected(network))
         {
             return(false);
         }
     }
     return(true);
 }
Exemple #26
0
 /// <summary>
 /// Find and Load in the network data
 /// </summary>
 private void LoadNetworkData()
 {
     foreach (var dataSource in this.Root.NetworkData)
     {
         if (dataSource.NetworkType == this.NetworkType)
         {
             this.NetworkData = dataSource;
             return;
         }
     }
 }
Exemple #27
0
 /// <summary>
 /// Find and Load in the network data
 /// </summary>
 private void LoadNetworkData()
 {
     foreach ( var dataSource in this.Root.NetworkData )
     {
         if ( dataSource.NetworkType == this.NetworkType )
         {
             this.NetworkData = dataSource;
             return;
         }
     }
 }
 private void EnsureNetworks(INetworkData autoNetwork, ITripComponentData transitNetwork)
 {
     if (autoNetwork == null)
     {
         throw new XTMFRuntimeException("In '" + Name + "' we were unable to find an auto network named '" + AutoNetworkName + "'!");
     }
     if (transitNetwork == null)
     {
         throw new XTMFRuntimeException("In '" + Name + "' we were unable to find an transit network named '" + TransitNetworkName + "'!");
     }
 }
Exemple #29
0
 private void sendData(int connectionId, int channelId, EventType type, INetworkData data)
 {
     using (var stream = new MemoryStream()) {
         using (var writer = new BinaryWriter(stream)) {
             writer.Write((byte)type);
             data.Write(writer);
             var buffer = stream.ToArray();
             sendData(connectionId, channelId, buffer, buffer.Length);
         }
     }
 }
Exemple #30
0
 /// <summary>
 /// Send network data to all clients, except one
 /// </summary>
 /// <param name="exceptClient">Client, that shouldn`t receive data</param>
 /// <param name="data">Network data</param>
 private void SendDataExcept(ConnectedClient exceptClient, INetworkData data)
 {
     foreach (var client in _connectedClients.Values)
     {
         if (client == exceptClient)
         {
             continue;
         }
         _dataPackets[client.Id].Add(data);
     }
 }
Exemple #31
0
        /// <summary>
        /// Обработка полученных данных
        /// </summary>
        /// <param name="networkObject"></param>
        private void ProcessMessage(INetworkData networkObject)
        {
            switch (networkObject.NetworkObjectType)
            {
            case NetworkObjectTypes.Contacts:
            {
                var clientsCollection = (NetworkClientsCollection)networkObject;

                AddAllContacts(clientsCollection);
                break;
            }

            case NetworkObjectTypes.Message:
            {
                var message = (NetworkMessage)networkObject;

                AddMessage(message);
                break;
            }

            case NetworkObjectTypes.ClientInfo:
            {
                var networkClient = (NetworkClient)networkObject;

                AddContact(networkClient);
                break;
            }

            case NetworkObjectTypes.MessageDelivered:
            {
                var messageState = (NetworkMessageState)networkObject;
                var isDelivered  = messageState.IsDelivered;

                SetMessageState(isDelivered);

                break;
            }

            case NetworkObjectTypes.Command:
            {
                var networkCommand = (NetworkCommand)networkObject;

                if (networkCommand.CommandType == NetworkCommandTypes.Disconnect)
                {
                    CloseConnection();
                }
                if (networkCommand.CommandType == NetworkCommandTypes.ServerStop)
                {
                    ClientStop();
                }
                break;
            }
            }
        }
 /// <summary>
 /// Initialise a new instance of RequestNetworkData with specific parameters.
 /// </summary>
 /// <param name="type">The type of the request. Whether it's requesting data or NetworkId or something else.</param>
 /// <param name="data">The Network data to submit with the Request.</param>
 public RequestNetworkData(RequestNetworkDataType type, INetworkData data)
     : this(type, "")
 {
     _data = data;
 }
Exemple #33
0
 public bool RuntimeValidation(ref string error)
 {
     foreach(var network in Root.NetworkData)
     {
         if(network.NetworkType == AutoNetworkName)
         {
             AutoNetwork = network;
         }
         else if(network.NetworkType == TransitNetworkName)
         {
             TransitNetwork = network as ITripComponentData;
         }
     }
     if(AutoNetwork == null)
     {
         error = "In '" + Name + "' we were unable to find an auto network called '" + AutoNetworkName + "'";
         return false;
     }
     if(TransitNetwork == null)
     {
         error = "In '" + Name + "' we were unable to find a transit network called '" + TransitNetworkName + "'";
         return false;
     }
     return true;
 }
Exemple #34
0
        /// <summary>
        /// This is called before the start method as a way to pre-check that all of the parameters that are selected
        /// are in fact valid for this module.
        /// </summary>
        /// <param name="error">A string that should be assigned a detailed error</param>
        /// <returns>If the validation was successful or if there was a problem</returns>
        public bool RuntimeValidation(ref string error)
        {
            // if our deep ancestor is in fact a tasha runtime
            this.TashaRuntime = this.Root as ITashaRuntime;
            IList<INetworkData> networks;
            if(this.TashaRuntime == null)
            {
                // check for a 4Step model system template
                var tdm = this.Root as ITravelDemandModel;
                // if it isn't report the error
                if(tdm == null)
                {
                    error = "The Tasha.Modes.Auto Module only works with ITashaRuntime's and ITravelDemandModel's!";
                    return false;
                }
                networks = tdm.NetworkData;
            }
            else
            {
                if(String.IsNullOrWhiteSpace(this.VehicleTypeName))
                {
                    this.AutoType = this.TashaRuntime.AutoType;
                }
                else
                {
                    if(this.TashaRuntime.VehicleTypes != null)
                    {
                        foreach(var v in this.TashaRuntime.VehicleTypes)
                        {
                            if(v.VehicleName == this.VehicleTypeName)
                            {
                                this.AutoType = v;
                                break;
                            }
                        }
                    }
                }
                if(AutoType == null)
                {
                    error = "We were unable to find an vehicle type to use for '" + this.ModeName + "'!";
                    return false;
                }
                networks = this.TashaRuntime.NetworkData;
            }
            if(String.IsNullOrWhiteSpace(this.NetworkType))
            {
                error = "There was no network type selected for the " + (String.IsNullOrWhiteSpace(this.ModeName) ? "Auto" : this.ModeName) + " mode!";
                return false;
            }
            if(networks == null)
            {
                error = "There was no Auto Network loaded for the Auto Mode!";
                return false;
            }
            bool found = false;
            foreach(var network in networks)
            {
                if(network.NetworkType == this.NetworkType)
                {
                    this.AutoData = network;
                    found = true;
                    break;
                }
            }
            if(!found)
            {
                error = "In '" + Name + "' we were unable to find the network data with the name \"" + this.NetworkType + "\" in this Model System!";
                return false;
            }

            return true;
        }
Exemple #35
0
 /// <summary>
 /// This is called before the start method as a way to pre-check that all of the parameters that are selected
 /// are in fact valid for this module.
 /// </summary>
 /// <param name="error">A string that should be assigned a detailed error</param>
 /// <returns>If the validation was successful or if there was a problem</returns>
 public bool RuntimeValidation(ref string error)
 {
     if ( this.Root == null )
     {
         error = "The Root Model System for the taxi mode was never loaded!";
         return false;
     }
     if ( this.Root.NetworkData == null )
     {
         error = "There was no network data in this model system to load from!";
         return false;
     }
     bool found = false;
     foreach ( var data in this.Root.NetworkData )
     {
         if ( data.NetworkType == this.AutoNetworkName )
         {
             found = true;
             this.data = data;
             break;
         }
     }
     if ( !found )
     {
         error = String.Concat( "We could not find any data named ", this.AutoNetworkName, " to load as the auto network data for the Taxi mode!" );
         return false;
     }
     return true;
 }
Exemple #36
0
 protected float GetTravelLogsum(INetworkData autoNetwork, ITripComponentData transitNetwork, int i, int j, Time time)
 {
     float ivtt, cost;
     if(!autoNetwork.GetAllData(i, j, time, out ivtt, out cost))
     {
         return 0.0f;
     }
     return (float)(GetTransitUtility(transitNetwork, i, j, time)
         + Math.Exp(ivtt * AutoTime + cost * Cost));
 }
Exemple #37
0
        public bool RuntimeValidation(ref string error)
        {
            foreach ( var network in this.Root.NetworkData )
            {
                if ( network.Name == this.AccessModeName )
                {
                    this.First = network;
                }

                if ( network.Name == this.PrimaryModeName )
                {
                    var temp = network as ITripComponentData;
                    this.Second = temp == null ? this.Second : temp;
                }

                if ( network.NetworkType == this.EgressNetworkName )
                {
                    var temp = network as ITripComponentData;
                    this.Third = temp == null ? this.Third : temp;
                }
            }
            if ( this.First == null )
            {
                error = "In '" + this.Name + "' the name of the access network data type was not found!";
                return false;
            }
            else if ( this.Second == null )
            {
                error = "In '" + this.Name + "' the name of the primary network data type was not found or does not contain trip component data!";
                return false;
            }
            else if ( this.Third == null && this.ComputeEgressStation )
            {
                error = "In '" + this.Name + "' the name of the egress network data type was not found or does not contain trip component data!";
                return false;
            }
            return true;
        }
 public NetworkDataWarning(string message, INetworkData data, Exception innerException)
     : base(message, innerException)
 {
     _data = data;
 }
 public NetworkDataWarning(string message, INetworkData data)
     : this(message, data, null)
 {
 }
Exemple #40
0
 private bool AssignNetwork(IList<INetworkData> networks)
 {
     foreach(var network in networks)
     {
         if(network.NetworkType == NetworkType)
         {
             Network = network;
             return true;
         }
     }
     return false;
 }
Exemple #41
0
 /// <summary>
 /// This is called before the start method as a way to pre-check that all of the parameters that are selected
 /// are in fact valid for this module.
 /// </summary>
 /// <param name="error">A string that should be assigned a detailed error</param>
 /// <returns>If the validation was successful or if there was a problem</returns>
 public bool RuntimeValidation(ref string error)
 {
     var networks = this.TashaRuntime.NetworkData;
     if ( networks == null )
     {
         error = "There was no Auto Network loaded for the Passenger Mode!";
         return false;
     }
     bool found = false;
     foreach ( var network in networks )
     {
         if ( network.NetworkType == this.NetworkType )
         {
             this.AutoData = network;
             found = true;
             break;
         }
     }
     if ( !found )
     {
         error = "We were unable to find the network data with the name \"Auto\" in this Model System!";
         return false;
     }
     return true;
 }
Exemple #42
0
 /// <summary>
 /// Find and Load in the network data
 /// </summary>
 private void LoadNetworkData()
 {
     foreach ( var dataSource in this.Root.NetworkData )
     {
         if ( dataSource.NetworkType == this.NetworkType )
         {
             this.NetworkData = dataSource;
             ITripComponentData advancedData = dataSource as ITripComponentData;
             if ( advancedData != null )
             {
                 this.AdvancedNetworkData = advancedData;
             }
             break;
         }
     }
 }
Exemple #43
0
        public bool RuntimeValidation(ref string error)
        {
            if ( String.IsNullOrWhiteSpace( this.ModeName ) )
            {
                error = "In module '" + this.Name + "', please add in a 'Mode Name' for your nested choice!";
                return false;
            }
            if ( this.Correlation > 1 || this.Correlation < 0 )
            {
                error = "Correlation must be between 0 and 1 for " + this.ModeName + "!";
                return false;
            }
            if ( MaxAccessStations <= 0 )
            {
                error = "The number of feasible access stations must be greater than 0!";
                return false;
            }
            foreach ( var network in this.Root.NetworkData )
            {
                if ( network.NetworkType == this.AccessModeName )
                {
                    this.First = network;
                }

                if ( network.NetworkType == this.PrimaryModeName )
                {
                    var temp = network as ITripComponentData;
                    this.Second = temp == null ? this.Second : temp;
                }

                if ( network.NetworkType == this.EgressNetworkName )
                {
                    var temp = network as ITripComponentData;
                    this.Third = temp == null ? this.Third : temp;
                }

                if ( network.NetworkType == this.AlternativePrimaryModeName )
                {
                    this.FirstAlternative = network;
                }
            }
            if ( this.First == null )
            {
                error = "In '" + this.Name + "' the name of the access network data type was not found!";
                return false;
            }
            else if ( this.Second == null )
            {
                error = "In '" + this.Name + "' the name of the primary network data type was not found or does not contain trip component data!";
                return false;
            }
            else if ( this.Third == null && this.ComputeEgressStation )
            {
                error = "In '" + this.Name + "' the name of the egress network data type was not found or does not contain trip component data!";
                return false;
            }
            return true;
        }
Exemple #44
0
 private bool LoadNetwork()
 {
     foreach ( var data in this.Root.NetworkData )
     {
         if ( data.NetworkType == this.AutoNetworkName )
         {
             this.NetworkData = data;
             return true;
         }
     }
     return false;
 }
Exemple #45
0
        public bool RuntimeValidation(ref string error)
        {
            if(!ProfessionalFullTime.CheckResourceType<SparseArray<float>>())
            {
                error = "In '" + Name + "' the sub module Professional Full Time was not of type SparseArray<float>!";
                return false;
            }
            if(!ProfessionalPartTime.CheckResourceType<SparseArray<float>>())
            {
                error = "In '" + Name + "' the sub module Professional Part Time was not of type SparseArray<float>!";
                return false;
            }
            if(!ManufacturingFullTime.CheckResourceType<SparseArray<float>>())
            {
                error = "In '" + Name + "' the sub module Manufacturing Full Time was not of type SparseArray<float>!";
                return false;
            }
            if(!ManufacturingPartTime.CheckResourceType<SparseArray<float>>())
            {
                error = "In '" + Name + "' the sub module Manufacturing Part Time was not of type SparseArray<float>!";
                return false;
            }
            if(!GeneralFullTime.CheckResourceType<SparseArray<float>>())
            {
                error = "In '" + Name + "' the sub module General Full Time was not of type SparseArray<float>!";
                return false;
            }
            if(!GeneralPartTime.CheckResourceType<SparseArray<float>>())
            {
                error = "In '" + Name + "' the sub module General Part Time was not of type SparseArray<float>!";
                return false;
            }
            if(!RetailFullTime.CheckResourceType<SparseArray<float>>())
            {
                error = "In '" + Name + "' the sub module Retail Full Time was not of type SparseArray<float>!";
                return false;
            }
            if(!RetailPartTime.CheckResourceType<SparseArray<float>>())
            {
                error = "In '" + Name + "' the sub module Retail Part Time was not of type SparseArray<float>!";
                return false;
            }
            foreach(var network in Root.NetworkData)
            {
                if(network.NetworkType == AutoNetworkName)
                {
                    AutoNetwork = network;
                    break;
                }
            }
            if(AutoNetwork == null)
            {
                error = "In '" + Name + "' we were unable to find a network called '" + AutoNetworkName + "'";
            }

            foreach(var network in Root.NetworkData)
            {
                if(network.NetworkType == TransitNetworkName)
                {
                    TransitNetwork = network as ITripComponentData;
                    break;
                }
            }
            if(TransitNetwork == null)
            {
                error = "In '" + Name + "' we were unable to find a network called '" + AutoNetworkName + "'";
            }
            return true;
        }
Exemple #46
0
 private bool FindAutoData(ref string error)
 {
     IList<INetworkData> networks;
     networks = this.Root.NetworkData;
     if ( String.IsNullOrWhiteSpace( this.NetworkType ) )
     {
         error = "There was no network type selected for the " + ( String.IsNullOrWhiteSpace( this.ModeName ) ? "Auto" : this.ModeName ) + " mode!";
         return false;
     }
     if ( networks == null )
     {
         error = "There was no Auto Network loaded for the Auto Mode!";
         return false;
     }
     bool found = false;
     foreach ( var network in networks )
     {
         if ( network.NetworkType == this.NetworkType )
         {
             this.AutoData = network;
             found = true;
             break;
         }
     }
     if ( !found )
     {
         error = "We were unable to find the network data with the name \"" + this.NetworkType + "\" in this Model System!";
         return false;
     }
     return true;
 }
 public NetworkDataException(string message, INetworkData data)
     : this(message, data, null)
 {
 }
Exemple #48
0
        public bool RuntimeValidation(ref string error)
        {
            foreach ( var network in this.Root.NetworkData )
            {
                if ( network.NetworkType == Auto )
                {
                    this.AutoData = network;
                }

                else if ( network.NetworkType == Transit )
                {
                    var temp = network as ITripComponentData;
                    this.TransitData = temp == null ? this.TransitData : temp;
                }
            }
            return true;
        }
Exemple #49
0
 private void EnsureNetworks(INetworkData autoNetwork, ITripComponentData transitNetwork)
 {
     if(autoNetwork == null)
     {
         throw new XTMFRuntimeException("In '" + Name + "' we were unable to find an auto network named '" + AutoNetworkName + "'!");
     }
     if(transitNetwork == null)
     {
         throw new XTMFRuntimeException("In '" + Name + "' we were unable to find an transit network named '" + TransitNetworkName + "'!");
     }
 }
Exemple #50
0
 private float ComputeUtility(INetworkData autoNetwork, int originIndex, int destinationIndex)
 {
     float aivtt, cost;
     autoNetwork.GetAllData(originIndex, destinationIndex, StartTime, out aivtt, out cost);
     return AIVTT * aivtt + AutoCost * cost;
 }
 public NetworkDataException(string message, INetworkData data)
     : base(message)
 {
     _data = data;
 }
 private void SaveData(INetworkData autoData)
 {
 }