Example #1
0
 public void LoadData()
 {
     BinaryHelpers.ExecuteReader(this, (reader) =>
     {
         var matrix = new EmmeMatrix(reader);
         if (matrix.Dimensions != 2)
         {
             throw new XTMFRuntimeException(this, "In '" + Name + "' the matrix loaded in from '" + MatrixFile + "' was not an OD binary matrix!");
         }
         Data   = SparseTwinIndex <float> .CreateSquareTwinIndex(matrix.Indexes[0], matrix.Indexes[1], matrix.FloatData);
         Loaded = true;
     }, MatrixFile);
 }
Example #2
0
 private static void CopyMatrix(IZone[] zones, string origin, string destination)
 {
     try
     {
         BinaryHelpers.ExecuteReader((reader =>
         {
             var matrix = new EmmeMatrix(reader);
             SaveData.SaveMatrix(zones, matrix.FloatData, destination);
         }), origin);
     }
     catch (IOException)
     {
     }
 }
            internal void Execute(int iteration)
            {
                BinaryHelpers.ExecuteReader(this, (reader) =>
                {
                    EmmeMatrix matrix = new EmmeMatrix(reader);
                    switch (matrix.Type)
                    {
                    case EmmeMatrix.DataType.Float:
                        ProcessData(matrix.FloatData, iteration);
                        break;

                    default:
                        throw new XTMFRuntimeException(this, "In '" + Name + "' the data type for the file '" + DemandMatrix + "' was not float!");
                    }
                }, DemandMatrix);
            }
Example #4
0
        private static void CopySummedMatrix(IZone[] zones, string[] origins, string destination)
        {
            var array = new float[zones.Length * zones.Length];

            try
            {
                for (int i = 0; i < origins.Length; i++)
                {
                    BinaryHelpers.ExecuteReader((reader =>
                    {
                        var matrix = new EmmeMatrix(reader);
                        AddToArray(array, matrix.FloatData);
                    }), origins[i]);
                }
                SaveData.SaveMatrix(zones, array, destination);
            }
            catch (IOException)
            {
            }
        }
Example #5
0
        public IEnumerable <ODData <float> > Read()
        {
            var zones = this.Root.ZoneSystem.ZoneArray.GetFlatData();

            using (BinaryReader reader = new BinaryReader(new FileStream(InputFile, FileMode.Open, FileAccess.Read)))
            {
                EmmeMatrix matrix = new EmmeMatrix(reader);
                if (!matrix.IsValidHeader())
                {
                    throw new XTMFRuntimeException("In '" + this.Name + "' we were unable to load the matrix '" + (string)InputFile + "'");
                }
                ODData <float> result             = new ODData <float>();
                int            pos                = 0;
                var            indexes            = matrix.Indexes;
                var            originIndexes      = indexes[0];
                var            destinationIndexes = indexes[1];
                switch (matrix.Type)
                {
                case EmmeMatrix.DataType.Float:
                {
                    var data = matrix.FloatData;
                    for (int i = 0; i < originIndexes.Length; i++)
                    {
                        result.O = originIndexes[i];
                        for (int j = 0; j < destinationIndexes.Length; j++)
                        {
                            result.D    = destinationIndexes[j];
                            result.Data = data[pos++];
                            yield return(result);
                        }
                    }
                }
                break;

                case EmmeMatrix.DataType.Double:
                {
                    var data = matrix.DoubleData;
                    for (int i = 0; i < originIndexes.Length; i++)
                    {
                        result.O = originIndexes[i];
                        for (int j = 0; j < destinationIndexes.Length; j++)
                        {
                            result.D    = destinationIndexes[j];
                            result.Data = (float)data[pos++];
                            yield return(result);
                        }
                    }
                }
                break;

                case EmmeMatrix.DataType.SignedInteger:
                {
                    var data = matrix.SignedIntData;
                    for (int i = 0; i < originIndexes.Length; i++)
                    {
                        result.O = originIndexes[i];
                        for (int j = 0; j < destinationIndexes.Length; j++)
                        {
                            result.D    = destinationIndexes[j];
                            result.Data = data[pos++];
                            yield return(result);
                        }
                    }
                }
                break;

                case EmmeMatrix.DataType.UnsignedInteger:
                {
                    var data = matrix.UnsignedIntData;
                    for (int i = 0; i < originIndexes.Length; i++)
                    {
                        result.O = originIndexes[i];
                        for (int j = 0; j < destinationIndexes.Length; j++)
                        {
                            result.D    = destinationIndexes[j];
                            result.Data = data[pos++];
                            yield return(result);
                        }
                    }
                }
                break;
                }
            }
        }
Example #6
0
        public void Start()
        {
            var matrix = new EmmeMatrix(Root.ZoneSystem.ZoneArray, MatrixToSave.AquireResource <SparseTwinIndex <float> >().GetFlatData());

            matrix.Save(OutputFile, true);
        }
Example #7
0
        public void Start()
        {
            var matrix = new EmmeMatrix(Root.ZoneSystem.ZoneArray, ModuleHelper.GetDataFromDatasourceOrResource(MatrixToSaveRaw, MatrixToSave, MatrixToSaveRaw != null).GetFlatData());

            matrix.Save(OutputFile, true);
        }
Example #8
0
        public IEnumerable <ODData <float> > Read()
        {
            if (!File.Exists(InputFile))
            {
                throw new XTMFRuntimeException(this, $"Unable to read an EMME Binary Matrix located at {InputFile.GetFilePath()}");
            }
            using (BinaryReader reader = new BinaryReader(new FileStream(InputFile, FileMode.Open, FileAccess.Read)))
            {
                EmmeMatrix matrix = new EmmeMatrix(reader);
                if (!matrix.IsValidHeader())
                {
                    throw new XTMFRuntimeException(this, "In '" + Name + "' we were unable to load the matrix '" + InputFile + "'");
                }
                ODData <float> result             = new ODData <float>();
                int            pos                = 0;
                var            indexes            = matrix.Indexes;
                var            originIndexes      = indexes[0];
                var            destinationIndexes = indexes[1];
                switch (matrix.Type)
                {
                case EmmeMatrix.DataType.Float:
                {
                    var data = matrix.FloatData;
                    for (int i = 0; i < originIndexes.Length; i++)
                    {
                        result.O = originIndexes[i];
                        for (int j = 0; j < destinationIndexes.Length; j++)
                        {
                            result.D    = destinationIndexes[j];
                            result.Data = data[pos++];
                            yield return(result);
                        }
                    }
                }
                break;

                case EmmeMatrix.DataType.Double:
                {
                    var data = matrix.DoubleData;
                    for (int i = 0; i < originIndexes.Length; i++)
                    {
                        result.O = originIndexes[i];
                        for (int j = 0; j < destinationIndexes.Length; j++)
                        {
                            result.D    = destinationIndexes[j];
                            result.Data = (float)data[pos++];
                            yield return(result);
                        }
                    }
                }
                break;

                case EmmeMatrix.DataType.SignedInteger:
                {
                    var data = matrix.SignedIntData;
                    for (int i = 0; i < originIndexes.Length; i++)
                    {
                        result.O = originIndexes[i];
                        for (int j = 0; j < destinationIndexes.Length; j++)
                        {
                            result.D    = destinationIndexes[j];
                            result.Data = data[pos++];
                            yield return(result);
                        }
                    }
                }
                break;

                case EmmeMatrix.DataType.UnsignedInteger:
                {
                    var data = matrix.UnsignedIntData;
                    for (int i = 0; i < originIndexes.Length; i++)
                    {
                        result.O = originIndexes[i];
                        for (int j = 0; j < destinationIndexes.Length; j++)
                        {
                            result.D    = destinationIndexes[j];
                            result.Data = data[pos++];
                            yield return(result);
                        }
                    }
                }
                break;
                }
            }
        }