public void Print(string content) { Delegate[] delegates = Log?.GetInvocationList(); // delegates[1] = null; // LogConsole($"Printing... {content}"); // LogFile($"Printing... {content}"); //if (Log!=null) // Log($"Printing... {content}"); Log?.Invoke($"Printing... {content}"); // .. // LogConsole($"Printed."); Log?.Invoke($"Printed."); Finish?.Invoke(10); decimal?cost = CalculateCost?.Invoke(10); if (cost.HasValue) { Display(cost.Value); } Completed?.Invoke(); Error?.Invoke(this, EventArgs.Empty); }
void _test_Click(object sender, RoutedEventArgs e) { int num = 0; double min = 0, max = 0; bool parsed = int.TryParse(this._interval.Text, out num) && double.TryParse(this._MAX.Text, out max) && double.TryParse(this._MIN.Text, out min); if (!parsed) { MessageBox.Show("Invalid input range or interval"); return; } if (num < 2) { MessageBox.Show("Interval should be larger than 1"); return; } this._min = min; this._max = max; try { this._graphs._graphsHost.Clear(); PointCollection points = new PointCollection(); double yMax = double.NegativeInfinity; double yMin = double.PositiveInfinity; double d = (this._max - this._min) / num; double t = this._min; for (int i = 0; i <= num; i++) { double yVal = this.CostFunction(t); if (yVal == double.MaxValue || yVal == double.MinValue || yVal == double.NaN || yVal == double.NegativeInfinity || yVal == double.PositiveInfinity) { throw new ArgumentException(yVal.ToString() + " is not a valid output for the cost function"); } Point pnt = new Point(t, yVal); t += d; points.Add(pnt); yMax = (yMax < yVal) ? yVal : yMax; yMin = (yMin > yVal) ? yVal : yMin; } this._graphs._yMax.Text = yMax.ToString(); this._graphs._yMin.Text = yMin.ToString(); this._graphs._xMin.Text = this._min.ToString(); this._graphs._xMax.Text = this._max.ToString(); if (yMax - yMin < .01) { throw new ArgumentException(string.Format("f(x) = {0}\n\tWPF Charts does not support drawing it!", ((yMax + yMin) / 2).ToString())); } this._graphs._graphsHost.AddTrendLine(points); } catch (Exception error) { this.CostFunction = null; MessageBox.Show(error.Report()); return; } }
public void GetNextFrame() { var calCulateCost = new CalculateCost(); float bestScore = float.MaxValue; int bestScoreClipIndex = 0; int bestScoreFrameIndex = 0; float normalizedTime = 0; MotionClipData motionClipData = MotionClips[0]; int frameIndex = 0; GetPlayerMotion(PlayerInput, timer); for (int i = 0; i < MotionClips.Count; i++) { //var normalizedTime = (timer % MotionClips[i].MotionClipLengthInMilliseconds) / MotionClips[i].MotionClipLengthInMilliseconds; if (MotionClips[i].ClipType != NowClipType) { continue; } for (int j = 0; j < MotionClips[i].MotionFrames.Length; j++) { var thisMotionScore = calCulateCost.CalculateAllCost(MotionClips[i].MotionFrames[j], PlayerMotionFrame, playerSetting); if (thisMotionScore < Mathf.Epsilon)// Mathf.Epsilon { continue; } if (thisMotionScore < bestScore) { bestScore = thisMotionScore; bestScoreClipIndex = i; bestScoreFrameIndex = j; normalizedTime = (timer % MotionClips[i].MotionClipLengthInMilliseconds) / MotionClips[i].MotionClipLengthInMilliseconds; frameIndex = Mathf.FloorToInt(MotionClips[i].MotionFrames.Length * normalizedTime); motionClipData = MotionClips[i]; } } } // Debug.Log("best frame"); // Debug.Log(bestScoreFrameIndex); //PlayerMotionFrame = MotionClips[bestScoreClipIndex].MotionFrames[bestScoreFrameIndex]; // NextFrame.Value = MotionClips[bestScoreClipIndex].MotionFrames[bestScoreFrameIndex]; test_playAnimation(frameIndex, motionClipData); MotionName = motionClipData.Name; }
/// <summary> /// Initializes a new instance of the <see cref="VisualizeFunction"/> class. /// </summary> /// <param name="function">The function.</param> public VisualizeFunction(Function function) { InitializeComponent(); this._name.Text = function.Name; SpatialDataField data = function as SpatialDataField; if (data != null) { this._min = data.Min; this._max = data.Max; this._MIN.IsEnabled = false; this._MAX.IsEnabled = false; } else { this._min = 0; this._max = 10; } this._MIN.Text = this._min.ToString(); this._MAX.Text = this._max.ToString(); this.CostFunction = function.GetCost; this._test.Click += new RoutedEventHandler(_test_Click); this._close.Click += new RoutedEventHandler(_close_Click); }
private void btnTest_Click(object sender, EventArgs e) { #region Testing Code - Don't Delete...Might need //tbLog.Clear();//just for debug //double soldShareCost = 0; //double remainingShareCost = 0; //int sharesSold = Convert.ToInt32(tbSharesSold.Text); //int remainingshares = 0; //foreach (Share share in qShares) //{ // if (sharesSold > 0) // { // if (sharesSold >= share.ShareCount) // { // soldShareCost += share.ShareCount * share.SharePrice; // } // else if (sharesSold < share.ShareCount) // { // soldShareCost += sharesSold * share.SharePrice; // remainingShareCost = (share.ShareCount - sharesSold) * share.SharePrice; // } // } // else // { // remainingShareCost += share.ShareCount * share.SharePrice; // } // sharesSold -= share.ShareCount; //} //remainingshares = sharesSold * -1; //lblRemainingSharesResult.Text = remainingshares.ToString(); //lblSoldSharesCostResult.Text = (soldShareCost / Convert.ToInt32(tbSharesSold.Text)).ToString(); //lblSaleGainLossResults.Text = (Convert.ToDouble(tbSharesSold.Text) * Convert.ToDouble(tbPricePerShare.Text) - soldShareCost).ToString(); //lblRemainingSharesCostResults.Text = (remainingShareCost / remainingshares).ToString(); //tbLog.Text += (remainingShareCost / remainingshares).ToString(); #endregion CalculateCost cc = new CalculateCost(); int totalShareCount = _SharesList.Sum(x => x.ShareCount); //Total number of shares int soldShareCount = Convert.ToInt32(tbSharesSold.Text); //Shares Sold if (soldShareCount <= totalShareCount) { double soldShareCost = 0; //cost per share double remainingShareCost = 0; //Remaining Share Count int sharesSold = Convert.ToInt32(tbSharesSold.Text); //how much the user is selling int remainingShares = 0; foreach (Share share in _SharesList) { if (sharesSold > 0) { if (sharesSold >= share.ShareCount) { soldShareCost += cc.Cost(share.ShareCount, share.SharePrice); } else if (sharesSold < share.ShareCount) { soldShareCost += _Calculator.Cost(sharesSold, share.SharePrice); remainingShareCost = _Calculator.Cost((share.ShareCount - sharesSold), share.SharePrice); } } else { remainingShareCost += cc.Cost(share.ShareCount, share.SharePrice); } sharesSold -= share.ShareCount; } remainingShares = Math.Abs(sharesSold);//Absolute value for amount to work with //display lblRemainingSharesResult.Text = remainingShares.ToString(); //amount left lblSoldSharesCostResult.Text = (soldShareCost / Convert.ToInt32(tbSharesSold.Text)).ToString(); //Cost for Sold Shares CalculatePnL cpnl = new CalculatePnL(); lblSaleGainLossResults.Text = (cpnl.PnL(Convert.ToInt32(tbSharesSold.Text), Convert.ToDouble(tbPricePerShare.Text), soldShareCost)).ToString(); lblRemainingSharesCostResults.Text = (remainingShareCost / remainingShares).ToString();//Cost Remaining Shares } }
//https://github.com/pieterderycke/Jace/wiki /// <summary> /// Sets the string formula. /// </summary> /// <param name="calculateCost">The calculate cost.</param> public void SetStringFormula(CalculateCost calculateCost) { this.GetCost = null; this.GetCost = calculateCost; this.CostCalculationType = CostCalculationMethod.WrittenFormula; }
void _close_Click(object sender, RoutedEventArgs e) { this._graphs._graphsHost.Clear(); this.CostFunction = null; this.Close(); }