/// <summary> /// Defines this cell as an output cell for a scenario /// </summary> /// <returns></returns> public OutputCell ToOutputCell() { var cell = new OutputCell() { Id = Id, Content = Content, Location = Location, SifLocation = SifLocation }; return(cell); }
private List <GridObject> SolveOutput(OutputCell _outputCell, List <GridObject> _checkedObjects) { GridObject entry = GetCell(_outputCell.Entry); if (!_checkedObjects.Contains(entry)) { Debug.LogError("GridManager: SolveOutput encountered an output whose entry has not been solved!"); return(null); } _outputCell.CurrentValues = new int[] { entry.GetValueForCoordinate(_outputCell.Coordinates[0]) }; // Assumes outputs are 1x1 return(null); }
private bool AddNextOutput() { if (m_futureOutputs.Count > 0) { OutputCell output = m_futureOutputs[0]; InsertObject(output); Debug.Log("GridManager: Output added - " + output.Coordinates[0].ToString() + " target " + output.OutputTarget); m_outputs.Add(output); m_futureOutputs.RemoveAt(0); return(true); } return(false); }
private IOutputCell <T> Map(Cell <T> cell, KeyTuplePairs <T> tuples, Query <T> query) { var ocell = new OutputCell <T>(cell.Coords, tuples.XAnchorTuple, tuples.YAnchorTuple); foreach (var item in query.MeasuresOrMetrics) { var dataItem = _resolver.GetDataItemInfo(item); var value = cell.Values[item]; ocell.Add(dataItem.Name, value); } return(ocell); }
/// <summary> /// Sets up the model outputs /// </summary> /// <param name="initialisation">An instance of the model initialisation class</param> /// <param name="simulation">The index of the simulation being run</param> /// <param name="scenarioIndex">The index of the scenario being run</param> public void SetUpOutputs(MadingleyModelInitialisation initialisation, int simulation, int scenarioIndex) { // Initialise the global outputs GlobalOutputs = new OutputGlobal(InitialisationFileStrings["OutputDetail"], initialisation); // Create new outputs class instances (if the model is run for the whold model grid then select the grid view for the live output, // if the model is run for specific locations then use the graph view) if (SpecificLocations) { // Initialise the vector of outputs instances CellOutputs = new OutputCell[_CellList.Count]; for (int i = 0; i < _CellList.Count; i++) { CellOutputs[i] = new OutputCell(InitialisationFileStrings["OutputDetail"], initialisation, i); } #if false // Spawn a dataset viewer instance for each cell to display live model results if (initialisation.LiveOutputs) { for (int i = 0; i < _CellList.Count; i++) { CellOutputs[i].SpawnDatasetViewer(NumTimeSteps); } } #endif } else { GridOutputs = new OutputGrid(InitialisationFileStrings["OutputDetail"], initialisation); #if false // Spawn dataset viewer to display live grid results if (initialisation.LiveOutputs) { GridOutputs.SpawnDatasetViewer(); } #endif } }
private void GenerateOutput(bool _insert) { uint x = DimensionX + 1; uint y = (uint)Random.Range(1, DimensionY); int target = Random.Range(1, MaxOutputTarget + 1); while (GetCell(new CellCoordinates(x, y)) != null) { y = (uint)Random.Range(1, DimensionY); } OutputCell output = (new OutputCell(new CellCoordinates(x, y), ObjectOrientation.Or0, target)); if (_insert) { m_outputs.Add(output); InsertObject(output); Debug.Log("GridManager: Output added - " + output.Coordinates[0].ToString() + " target " + output.OutputTarget); } else { m_futureOutputs.Add(output); } }
// // test 3: // test outputs static void test3() { MindClock clk = new MindClock(); Cell a = new Cell(clk); Queue<string> q = new Queue<string>(); OutputCell c = new OutputCell(q, "hello world", clk); a.connect_output(c); for(int i = 0; i < 11; i++) { a.upcharge(); } System.Console.WriteLine("a -> " + a + " (?1)"); System.Console.WriteLine("q -> " + q.Dequeue()); }
/// <summary> /// Defines this cell as an output cell for a scenario /// </summary> /// <returns></returns> public OutputCell ToOutputCell() { var cell = new OutputCell() { Id = Id, Content = Content, Location = Location, SifLocation = SifLocation }; return cell; }
private void PassThroughCell(CellCoordinates _cell) { if (m_passedThrough.Peek() != _cell) { CellCoordinates head = m_passedThrough.Pop(); if (_cell != head && IsAdjacentTo(_cell, head)) { // Wait till we move, and only consider if it is adjacent if (m_passedThrough.Count >= 1) { CellCoordinates prev = m_passedThrough.Pop(); if (_cell == prev) { // Early out if we went backwards Log("WireManager: Going backwards to " + _cell.ToString()); m_passedThrough.Push(prev); return; } m_passedThrough.Push(prev); } else { // This is the first move, assert that we head onto a valid OUTPUT of our starting gate GridObject gridObject = m_gridManager.GetCell(head); switch (gridObject.ObjectType) { case GridObjectType.Input: { InputCell input = (InputCell)gridObject; if (input.Exit != _cell) { m_passedThrough.Push(head); // Put the head back on and early out, this is not the exit cell return; } break; } case GridObjectType.Gate: { Gate gate = (Gate)gridObject; bool isValid = false; foreach (CellCoordinates output in gate.Outputs) { if (output == _cell) { isValid = true; } } if (!isValid) { m_passedThrough.Push(head); // We are not over any valid output cell, put the head back on and early out return; } break; } default: { Debug.LogError("WireManager: PassThrough found starting position that wasn't a Gate or Input."); m_passedThrough.Push(head); // Put the head back on and early out return; } } } m_passedThrough.Push(head); // Put the head back on, moving forwards GridObject headObject = m_gridManager.GetCell(head); if ((m_passedThrough.Count == 1 || headObject == null || (headObject.ObjectType != GridObjectType.Gate && headObject.ObjectType != GridObjectType.Output)) && !m_passedThrough.Contains(_cell)) { // Check we haven't been here before on this path, and that we haven't already arrived at a destination GridObject cellObject = m_gridManager.GetCell(_cell); if (cellObject == null) { // Cell is unoccupied, add it Log("WireManager: Passing through " + _cell.ToString()); m_passedThrough.Push(_cell); } else { // Need to check it's a valid goal and we arrived in an acceptable way switch (cellObject.ObjectType) { case GridObjectType.Gate: { Gate gate = (Gate)cellObject; bool isValid = false; foreach (CellCoordinates input in gate.Inputs) { if (input == head) { isValid = true; break; } } if (isValid) { // Head lines up with an input for this gate so add Gate as end point Log("WireManager: Passing through " + _cell.ToString()); m_passedThrough.Push(_cell); } else { return; } break; } case GridObjectType.Output: { OutputCell output = (OutputCell)cellObject; if (output.Entry == head) { // Entry of Output lines up with head, so add Output as end point Log("WireManager: Passing through " + _cell.ToString()); m_passedThrough.Push(_cell); } else { ; return; } break; } default: { return; } } } } return; } m_passedThrough.Push(head); // Put the head back on, no new additions } }
private bool IsConnected(bool _isOutput, CellCoordinates _coords, GridObject _startObject) { //Check Us GridObject gridObject = gridManager.GetCell(_coords); if (gridObject != null) { switch (gridObject.ObjectType) { case GridObjectType.Wire: { Wire wire = (Wire)gridObject; for (uint i = 0; i < _startObject.Coordinates.Length; ++i) { CellCoordinates toCompare = _isOutput ? wire.Entry : wire.Exit; if (_startObject.Coordinates[i] == toCompare) { return(true); } } break; } case GridObjectType.Input: { InputCell cell = (InputCell)gridObject; for (uint i = 0; i < _startObject.Coordinates.Length; ++i) { if (_startObject.Coordinates[i] == cell.Exit) { if (_startObject.ObjectType == GridObjectType.Gate) { Gate usAsGate = (Gate)gridManager.GetCell(_startObject.Coordinates[i]); foreach (CellCoordinates input in usAsGate.Inputs) { if (input == _coords) { return(true); } } } else { return(true); } } } break; } case GridObjectType.Output: { OutputCell cell = (OutputCell)gridObject; for (uint i = 0; i < _startObject.Coordinates.Length; ++i) { if (_startObject.Coordinates[i] == cell.Entry) { if (_startObject.ObjectType == GridObjectType.Gate) { Gate usAsGate = (Gate)gridManager.GetCell(_startObject.Coordinates[i]); foreach (CellCoordinates output in usAsGate.Outputs) { if (output == _coords) { return(true); } } } else { return(true); } } } break; } case GridObjectType.Gate: { Gate gateCell = (Gate)gridObject; for (uint i = 0; i < _startObject.Coordinates.Length; ++i) { for (uint j = 0; j < (_isOutput? gateCell.Inputs.Length : gateCell.Outputs.Length); ++j) { CellCoordinates[] toCompare = _isOutput ? gateCell.Inputs : gateCell.Outputs; if (_startObject.Coordinates[i] == toCompare[j]) { return(true); } } } break; } } } return(false); }