public IConstraint2 Create( Ir r, Is s, It t, Iψ ψ, IB B) { IConstraint2 constraint = null; try { constraint = new Constraint2( r, s, t, ψ, B); } catch (Exception exception) { this.Log.Error( exception.Message, exception); } return(constraint); }
public IConstraints8LConstraintElement Create( IdIndexElement dIndexElement, IsIndexElement sIndexElement, ItIndexElement tIndexElement, Ir r, Ix x, Iz z) { IConstraints8LConstraintElement constraintElement = null; try { constraintElement = new Constraints8LConstraintElement( dIndexElement, sIndexElement, tIndexElement, r, x, z); } catch (Exception exception) { this.Log.Error( exception.Message, exception); } return(constraintElement); }
public IConstraints1ConstraintElement Create( IsIndexElement sIndexElement, ItIndexElement tIndexElement, Ir r, IxHat xHat, Iz z) { IConstraints1ConstraintElement constraintElement = null; try { constraintElement = new Constraints1ConstraintElement( sIndexElement, tIndexElement, r, xHat, z); } catch (Exception exception) { this.Log.Error("Exception message: " + exception.Message + " and stacktrace " + exception.StackTrace); } return(constraintElement); }
public ISPObjectiveFunction Create( IObjectiveFactory objectiveFactory, Ipa pa, Ir r, ISPx x) { ISPObjectiveFunction objectiveFunction = null; try { objectiveFunction = new SPObjectiveFunction( objectiveFactory, pa, r, x); } catch (Exception exception) { this.Log.Error( exception.Message, exception); } return(objectiveFunction); }
public IConstraints2ConstraintElement Create( IsIndexElement sIndexElement, Ir r, IB B, Ib b) { IConstraints2ConstraintElement constraintElement = null; try { constraintElement = new Constraints2ConstraintElement( sIndexElement, r, B, b); } catch (Exception exception) { this.Log.Error( exception.Message, exception); } return(constraintElement); }
public IS2 Calculate( IS2ParameterElementFactory S2ParameterElementFactory, IS2Factory S2Factory, Id1 d1, Id2 d2, Ir r, It t, Ird1d2 rd1d2, IW W, Ix x, IΔ Δ) { return(S2Factory.Create( rd1d2.Value .Where(i => i.d1IndexElement.Value.Value.Value != i.d2IndexElement.Value.Value.Value) // rd1d2t1 .SelectMany(b => t.GetNthElementsAt( b.d1IndexElement.Value.Value.Value, t.GetT() - W.Value.Value.Value + b.d1IndexElement.Value.Value.Value, W.Value.Value.Value), (a, b) => Tuple.Create(a.rIndexElement, a.d1IndexElement, a.d2IndexElement, b)) // rd1d2t1t2 .SelectMany(b => t.GetNthElementsAt( b.Item3.Value.Value.Value, t.GetT() - W.Value.Value.Value + b.Item3.Value.Value.Value, W.Value.Value.Value), (a, b) => Tuple.Create(a.Item1, a.Item2, a.Item3, a.Item4, b)) .Select( i => Tuple.Create( i.Item1, i.Item2, i.Item3, i.Item4, i.Item5, // x(j, r, t) x.Value .Where(j => j.Value.Value.Value) .Select(j => Tuple.Create( Δ.GetSurgicalSpecialtyOfSurgeon(j.sIndexElement), j.rIndexElement, j.tIndexElement)) .Where(j => j.Item2 == i.Item1) .Select(j => j.Item1) .Distinct() .Count())) .Where(i => i.Item6 == 1) .Select(i => S2ParameterElementFactory .Create( i.Item1, i.Item2, i.Item3)) .ToImmutableList())); }
public MainWindow() { InitializeComponent(); DataContext = this; Ir = Data.Ir; If = Data.If; Is = Data.Is; Selected_Ir = Ir.FirstOrDefault(); Selected_If = If.FirstOrDefault(); Selected_Is = Is.FirstOrDefault(); }
public Constraints2ConstraintElement( IsIndexElement sIndexElement, Ir r, IB B, Ib b) { Expression LHS = Expression.Sum( r.Value .Select( x => b.Value[sIndexElement, x])); int RHS = B.GetElementAtAsint( sIndexElement); this.Value = LHS == RHS; }
public Constraints1ConstraintElement( IsIndexElement sIndexElement, ItIndexElement tIndexElement, Ir r, IxHat xHat, Iz z) { Expression LHS = Expression.Sum( r.Value .Select( y => xHat.Value[sIndexElement, y, tIndexElement])); Expression RHS = z.Value[sIndexElement, tIndexElement]; this.Value = LHS == RHS; }
public Ir Create( ImmutableList <IrIndexElement> value) { Ir index = null; try { index = new r( value); } catch (Exception exception) { this.Log.Error("Exception message: " + exception.Message + " and stacktrace " + exception.StackTrace); } return(index); }
public ITotalFinancialContribution Calculate( ITotalFinancialContributionFactory totalFinancialContributionFactory, Ipa pa, Ir r, ISPx x) { return(totalFinancialContributionFactory.Create( pa.Value .Select( i => r.GetElementAtAsdecimal( i.pIndexElement) * (decimal)x.GetElementAt( i.pIndexElement, i.aIndexElement)) .Sum())); }
public Ir Create( ImmutableList <IrIndexElement> value) { Ir index = null; try { index = new r( value); } catch (Exception exception) { this.Log.Error( exception.Message, exception); } return(index); }
public Constraint2( Ir r, Is s, It t, Iψ ψ, IB B) { Expression LHS = Expression.Sum( s.Value .Select(x => B.Value[x])); int RHS = r.GetR() * t.Value .Select(x => 1 - ψ.GetElementAtAsint(x)) .Sum(); this.Value = LHS == RHS; }
public Ir Create( ImmutableList <IrParameterElement> value) { Ir parameter = null; try { parameter = new r( value); } catch (Exception exception) { this.Log.Error( exception.Message, exception); } return(parameter); }
public SPObjectiveFunction( IObjectiveFactory objectiveFactory, Ipa pa, Ir r, ISPx x) { Expression expression = Expression.Sum( pa.Value .Select( i => (double)r.GetElementAtAsdecimal( i.pIndexElement) * x.Value[i.pIndexElement, i.aIndexElement])); Objective objective = objectiveFactory.Create( expression, ObjectiveSense.Maximize); this.Value = objective; }
public IS1 Calculate( IS1ParameterElementFactory S1ParameterElementFactory, IS1Factory S1Factory, Ir r, Ix x, IΔ Δ) { return(S1Factory.Create( r.Value .Select( i => Tuple.Create( i, x.Value .Where(j => j.rIndexElement == i && j.Value.Value.Value) .Select(j => j.sIndexElement) .Select(j => Δ.GetSurgicalSpecialtyOfSurgeon(j).Value) .Distinct() .Count())) .Where(i => i.Item2 > 1) .Select(i => S1ParameterElementFactory.Create(i.Item1)) .ToImmutableList())); }
/// \brief Reads and interprets data reported by the Wii Remote. /// \return On success, > 0, < 0 on failure, 0 if nothing has been recieved. /// /// Wii Remote reads function similarly to a Queue, in FIFO (first in, first out) order. /// For example, if two reports were sent since the last \c ReadWiimoteData() call, /// this call will only read and interpret the first of those two (and "pop" it off /// of the queue). So, in order to make sure you don't fall behind the Wiimote's update /// frequency, you can do something like this (in a game loop for example): /// /// \code /// Wii Remote wiimote; /// int ret; /// do /// { /// ret = wiimote.ReadWiimoteData(); /// } while (ret > 0); /// \endcode public int ReadWiimoteData() { byte[] buf = new byte[22]; int status = WiimoteManager.RecieveRaw(hidapi_handle, buf); if (status <= 0) { return(status); // Either there is some sort of error or we haven't recieved anything } int typesize = GetInputDataTypeSize((InputDataType)buf[0]); byte[] data = new byte[typesize]; for (int x = 0; x < data.Length; x++) { data[x] = buf[x + 1]; } if (WiimoteManager.Debug_Messages) { Debug.Log("Recieved: [" + buf[0].ToString("X").PadLeft(2, '0') + "] " + BitConverter.ToString(data)); } // Variable names used throughout the switch/case block byte[] buttons; byte[] accel; byte[] ext = null; byte[] ir; switch ((InputDataType)buf[0]) // buf[0] is the output ID byte { case InputDataType.STATUS_INFO: // done. buttons = new byte[] { data[0], data[1] }; byte flags = data[2]; byte battery_level = data[5]; Button.InterpretData(buttons); bool old_ext_connected = Status.ext_connected; byte[] total = new byte[] { flags, battery_level }; Status.InterpretData(total); if (expecting_status_report) { expecting_status_report = false; } else // We haven't requested any data report type, meaning a controller has connected. { SendDataReportMode(last_report_type); // If we don't update the data report mode, no updates will be sent } if (Status.ext_connected != old_ext_connected && Type != WiimoteType.PROCONTROLLER) { if (Status.ext_connected) // The Wii Remote doesn't allow reading from the extension identifier { // when nothing is connected. Debug.Log("An extension has been connected."); if (current_ext != ExtensionController.MOTIONPLUS) { ActivateExtension(); RequestIdentifyExtension(); // Identify what extension was connected. } else { ExpectingWiiMotionPlusSwitch = false; } } else { if (!ExpectingWiiMotionPlusSwitch) { _current_ext = ExtensionController.NONE; } Debug.Log("An extension has been disconnected."); } } break; case InputDataType.READ_MEMORY_REGISTERS: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); if (CurrentReadData == null) { Debug.LogWarning("Recived Register Read Report when none was expected. Ignoring."); return(status); } byte size = (byte)((data[2] >> 4) + 0x01); byte error = (byte)(data[2] & 0x0f); // Error 0x07 means reading from a write-only register // Offset 0xa600fa is for the Wii Motion Plus. This error code can be expected behavior in this case. if (error == 0x07) { if (CurrentReadData.Offset != 0xa600fa) { Debug.LogError("Wiimote reports Read Register error 7: Attempting to read from a write-only register (" + CurrentReadData.Offset.ToString("x") + "). Aborting read."); } CurrentReadData = null; return(status); } // lowOffset is reversed because the Wii Remote reports are in Big Endian order ushort lowOffset = BitConverter.ToUInt16(new byte[] { data[4], data[3] }, 0); ushort expected = (ushort)CurrentReadData.ExpectedOffset; if (expected != lowOffset) { Debug.LogWarning("Expected Register Read Offset (" + expected + ") does not match reported offset from Wii Remote (" + lowOffset + ")"); } byte[] read = new byte[size]; for (int x = 0; x < size; x++) { read[x] = data[x + 5]; } CurrentReadData.AppendData(read); if (CurrentReadData.ExpectedOffset >= CurrentReadData.Offset + CurrentReadData.Size) { CurrentReadData = null; } break; case InputDataType.ACKNOWLEDGE_OUTPUT_REPORT: buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); // TODO: doesn't do any actual error handling, or do any special code about acknowledging the output report. break; case InputDataType.REPORT_BUTTONS: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); break; case InputDataType.REPORT_BUTTONS_ACCEL: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); accel = new byte[] { data[0], data[1], data[2], data[3], data[4] }; Accel.InterpretData(accel); break; case InputDataType.REPORT_BUTTONS_EXT8: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); ext = new byte[8]; for (int x = 0; x < ext.Length; x++) { ext[x] = data[x + 2]; } if (_Extension != null) { _Extension.InterpretData(ext); } break; case InputDataType.REPORT_BUTTONS_ACCEL_IR12: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); accel = new byte[] { data[0], data[1], data[2], data[3], data[4] }; Accel.InterpretData(accel); ir = new byte[12]; for (int x = 0; x < 12; x++) { ir[x] = data[x + 5]; } Ir.InterpretData(ir); break; case InputDataType.REPORT_BUTTONS_EXT19: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); ext = new byte[19]; for (int x = 0; x < ext.Length; x++) { ext[x] = data[x + 2]; } if (_Extension != null) { _Extension.InterpretData(ext); } break; case InputDataType.REPORT_BUTTONS_ACCEL_EXT16: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); accel = new byte[] { data[0], data[1], data[2], data[3], data[4] }; Accel.InterpretData(accel); ext = new byte[16]; for (int x = 0; x < ext.Length; x++) { ext[x] = data[x + 5]; } if (_Extension != null) { _Extension.InterpretData(ext); } break; case InputDataType.REPORT_BUTTONS_IR10_EXT9: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); ir = new byte[10]; for (int x = 0; x < 10; x++) { ir[x] = data[x + 2]; } Ir.InterpretData(ir); ext = new byte[9]; for (int x = 0; x < 9; x++) { ext[x] = data[x + 12]; } if (_Extension != null) { _Extension.InterpretData(ext); } break; case InputDataType.REPORT_BUTTONS_ACCEL_IR10_EXT6: // done. buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); accel = new byte[] { data[0], data[1], data[2], data[3], data[4] }; Accel.InterpretData(accel); ir = new byte[10]; for (int x = 0; x < 10; x++) { ir[x] = data[x + 5]; } Ir.InterpretData(ir); ext = new byte[6]; for (int x = 0; x < 6; x++) { ext[x] = data[x + 15]; } if (_Extension != null) { _Extension.InterpretData(ext); } break; case InputDataType.REPORT_EXT21: // done. ext = new byte[21]; for (int x = 0; x < ext.Length; x++) { ext[x] = data[x]; } if (_Extension != null) { _Extension.InterpretData(ext); } break; case InputDataType.REPORT_INTERLEAVED: if (!ExpectingSecondInterleavedPacket) { ExpectingSecondInterleavedPacket = true; InterleavedDataBuffer = data; } else if (WiimoteManager.Debug_Messages) { Debug.LogWarning( "Recieved two REPORT_INTERLEAVED (" + InputDataType.REPORT_INTERLEAVED.ToString("x") + ") reports in a row! " + "Expected REPORT_INTERLEAVED_ALT (" + InputDataType.REPORT_INTERLEAVED_ALT.ToString("x") + "). Ignoring!" ); } break; case InputDataType.REPORT_INTERLEAVED_ALT: if (ExpectingSecondInterleavedPacket) { ExpectingSecondInterleavedPacket = false; buttons = new byte[] { data[0], data[1] }; Button.InterpretData(buttons); byte[] ir1 = new byte[18]; byte[] ir2 = new byte[18]; for (int x = 0; x < 18; x++) { ir1[x] = InterleavedDataBuffer[x + 3]; ir2[x] = data[x + 3]; } Ir.InterpretDataInterleaved(ir1, ir2); Accel.InterpretDataInterleaved(InterleavedDataBuffer, data); } else if (WiimoteManager.Debug_Messages) { Debug.LogWarning( "Recieved two REPORT_INTERLEAVED_ALT (" + InputDataType.REPORT_INTERLEAVED_ALT.ToString("x") + ") reports in a row! " + "Expected REPORT_INTERLEAVED (" + InputDataType.REPORT_INTERLEAVED.ToString("x") + "). Ignoring!" ); } break; } if (ext == null) { _RawExtension = null; } else { _RawExtension = new ReadOnlyArray <byte>(ext); } return(status); }
public Swizzle(Ir value, params int[] fields) { Value = value; Fields = fields; }
public void PowerOn() { // Start the computer with the control until poiting at the first control word this.ControlUnit.OnControlStateUpdated(); ConsoleKeyInfo key; ValueFormat displayFormat = ValueFormat.Binary; while (true) { // Left modules this.Clock.OutputState(); Mar.OutputState(displayFormat); Ram.OutputState(displayFormat); Rom.OutputState(displayFormat); Ir.OutputState(displayFormat); IrParam.OutputState(displayFormat); // BUS this.Bus.OutputState(); // Right modules ProgramCounter.OutputState(displayFormat); A.OutputState(displayFormat); Alu.OutputState(displayFormat); B.OutputState(displayFormat); Flags.OutputState(displayFormat); Out.OutputState(displayFormat); // Control Unit (bottom) ControlUnit.OutputState(); // User keys Console.SetCursorPosition(0, 23); Console.Write(String.Format("[S]tep - [N]ext Ins - [R]un - Clock {0}hz [+-] - Rese[t] - [D]isplay - E[x]it", this.Clock.FrequencyHz)); // Step the system if (this.Clock.ClockMode == IClock.Mode.Stepped || (this.Clock.ClockMode == IClock.Mode.Running && Console.KeyAvailable)) { key = Console.ReadKey(true); int freq; switch (key.Key) { case ConsoleKey.S: this.Clock.ClockMode = IClock.Mode.Stepped; this.Clock.Step(); break; case ConsoleKey.R: this.Clock.ClockMode = IClock.Mode.Running; break; case ConsoleKey.N: this.Clock.ClockMode = IClock.Mode.Stepped; this.Clock.Step(); while (this.ControlUnit.MicrostepCounter.Value != 3 && !this.Clock.IsHalted) { Thread.Sleep(1); this.Clock.Step(); } break; case ConsoleKey.Add: freq = this.Clock.FrequencyHz; if (freq <= 20) { freq++; } else if (freq <= 100) { freq += 5; } else { freq += 50; } if (freq > 500) { freq = 500; } this.Clock.FrequencyHz = freq; break; case ConsoleKey.Subtract: freq = this.Clock.FrequencyHz; if (freq <= 20) { freq--; } else if (freq <= 100) { freq -= 5; } else { freq -= 50; } if (freq < 1) { freq = 1; } this.Clock.FrequencyHz = freq; break; case ConsoleKey.T: Reset(); break; case ConsoleKey.D: switch (displayFormat) { case ValueFormat.Hex: displayFormat = ValueFormat.Decimal; break; case ValueFormat.Decimal: displayFormat = ValueFormat.Binary; break; case ValueFormat.Binary: displayFormat = ValueFormat.Hex; break; } break; case ConsoleKey.X: return; } if (this.Clock.ClockMode == IClock.Mode.Stepped) { if (key.Key == ConsoleKey.S) { } } else if (this.Clock.ClockMode == IClock.Mode.Running) { } } if (this.Clock.ClockMode == IClock.Mode.Running) { if (Clock.IsHalted) { Thread.Sleep(1000); } else { Thread.Sleep(1000 / this.Clock.FrequencyHz); } this.Clock.Step(); } } }
public Cast(Type type, Ir value) { Type = type; Value = value; }
public void ParallelTest1() { const int numThreads = 100; Task[] tasks = new Task[numThreads]; List <string> failedList = new List <string>(); Customer[] customers = new Customer[numThreads]; List <Customer> createdCustomers = new List <Customer>(); HashSet <int> ids = new HashSet <int>(); for (int i = 0; i < numThreads; i++) { string name = "C" + (i + 1); tasks[i] = Task.Run(() => { Customer customer = InsertRecord(new Customer { Name = name }); if (customer.CustomerID == 0) { lock (failedList) failedList.Add("CustomerID == 0"); } lock (ids) { if (ids.Contains(customer.CustomerID)) { failedList.Add($"Duplicate CustomerID {customer.CustomerID} for {customer.Name}"); } ids.Add(customer.CustomerID); } lock (createdCustomers) createdCustomers.Add(customer); var newCustomer = Ir.DataSet <Customer>().Read(customer.CustomerID); if (customer.Name != newCustomer.Name) { lock (failedList) failedList.Add($"Customer == ({newCustomer.CustomerID},{newCustomer.Name}), but should be ({customer.CustomerID},{customer.Name})"); } }); } foreach (var task in tasks) { task.Wait(); } foreach (var fail in failedList) { Assert.Fail(fail); } Assert.That(createdCustomers, Has.Count.EqualTo(numThreads)); }
public Swizzle(Ir value, IEnumerable <int> fields) { Value = value; Fields = fields.ToArray(); }
public MemberAccess(Ir value, string member) { Value = value; Member = member; }