public void LoadData() { var loadedSources = DataSources.Select(s => s.Loaded).ToArray(); try { var result = ExpressionToExecute.Evaluate(DataSources); if (result.Error) { throw new XTMFRuntimeException(this, "In '" + Name + "' an exception during the execution of the expression occurred.\r\n" + result.ErrorMessage); } // check to see if the result is a scalar if (result.IsValue) { if (Root != null) { var data = Root.ZoneSystem.ZoneArray.CreateSquareTwinArray <float>(); var flat = data.GetFlatData(); var row = flat[0]; var val = result.LiteralValue; for (int i = 0; i < row.Length; i++) { row[i] = val; } for (int i = 1; i < flat.Length; i++) { Array.Copy(row, flat[i], row.Length); } Data = data; } else { throw new XTMFRuntimeException(this, "In '" + Name + "' the result of the expression was a Scalar instead of a Matrix and there was no ITravelDemandModel in the ancestry to copy the zone system from!"); } } else if (result.IsVectorResult) { throw new XTMFRuntimeException(this, "In '" + Name + "' the result of the expression was a Vector instead of a matrix!"); } else { Data = result.OdData; } } finally { // unload the data sources that were loaded to evaluate the expression for (int i = 0; i < loadedSources.Length; i++) { if (!loadedSources[i] && DataSources[i].Loaded) { DataSources[i].UnloadData(); } } } Loaded = true; }
public void LoadData() { var loadedSources = DataSources.Select(s => s.Loaded).ToArray(); try { var result = ExpressionToExecute.Evaluate(DataSources); if (result.Error) { throw new XTMFRuntimeException(this, "In '" + Name + "' an exception during the execution of the expression occurred.\r\n" + result.ErrorMessage); } // check to see if the result is a scalar if (result.IsValue) { Data = result.LiteralValue; } else if (result.IsVectorResult) { throw new XTMFRuntimeException(this, "In '" + Name + "' the result of the expression was a Vector instead of a scalar!"); } else { throw new XTMFRuntimeException(this, "In '" + Name + "' the result of the expression was a Matrix instead of a scalar!"); } } finally { // unload the data sources that were loaded to evaluate the expression for (int i = 0; i < loadedSources.Length; i++) { if (!loadedSources[i] && DataSources[i].Loaded) { DataSources[i].UnloadData(); } } } Loaded = true; }