public Direction(Fuzzy dx, Fuzzy dy) { // normalize the vector along the smallest axis if (Fuzzy.Abs(dx) > Fuzzy.Abs(dy)) { this.dx = dy != 0 ? dx / Fuzzy.Abs(dy) : Fuzzy.Sign(dx); this.dy = Fuzzy.Sign(dy); } else { this.dx = Fuzzy.Sign(dx); this.dy = dx != 0 ? dy / Fuzzy.Abs(dx) : Fuzzy.Sign(dy); } }
public void CreateTest() { Assert.Equal(0.5, Fuzzy.Create(0.5).Value, MathConstants.Precision); Assert.Equal(0.0, Fuzzy.Create(-1.0).Value, MathConstants.Precision); Assert.Equal(1.0, Fuzzy.Create(2.0).Value, MathConstants.Precision); }
public void CreateMaxTest() { Assert.Equal(0.1, Fuzzy.Create(10, 100).Value, MathConstants.Precision); Assert.Equal(0.0, Fuzzy.Create(-1.0, 100).Value, MathConstants.Precision); Assert.Equal(1.0, Fuzzy.Create(200.0, 100).Value, MathConstants.Precision); }
public static Fuzzy ToFuzzy(this double value) => Fuzzy.Create(value);
Fuzzy fuzzy; //思考ルーチン // Use this for initialization void Start() { fuzzy = GetComponent <Fuzzy>(); personality = Random.Range(0, 2) == 0 ? Personality.NORMAL : Personality.HARD; }
private bool IsMirrorAt(Fuzzy x, Fuzzy y) { return grid[Fuzzy.Floor(x), Fuzzy.Floor(y)] == '#'; }
public void TestTokenSetPartialRatio(string s1, string s2, int expected) { Assert.Equal(expected, Fuzzy.TokenSetPartialRatio(s1, s2)); }
private Fuzzy GetNextPositionOnGrid(Fuzzy position, Fuzzy direction, double step) { // positive directon if (direction > 0) return Fuzzy.Floor(position / step + 1) * step; // negative directon if (direction < 0) return Fuzzy.Ceiling(position / step - 1) * step; // null direction return position; }
public void TestCaseSensitivePartialRatio(string s1, string s2, int expected) { Assert.Equal(expected, Fuzzy.PartialRatio(s1, s2, StringOptions.CaseSensitive, StringOptions.PreserveNonAlphaNumeric)); }
public void TestSpecialCharacterRatio() { Assert.Equal(96, Fuzzy.TokenSetRatio("Steve Ordonez", "Steve Ordoí±ez")); }
public override void Execute() { Simulation.Reschedule(this, Fuzzy.Value(1)); }
private static int GetColumnIndex(IEnumerable <string> columnNames, string v) { string match = Fuzzy.GetBestMatch(columnNames, v); return(columnNames.ToList().IndexOf(match) + 1); }
private void Start() { rigibody = GetComponent <Rigidbody> (); fuzzy = GetComponentInChildren <Fuzzy> (); carView = GetComponent <CarView> (); }
public fuzstate(T stateName, Fuzzy brain, float minDuration) : base(stateName, brain, minDuration) { this.brain = brain; }
public void TestWeightedRatio(string s1, string s2, int expected) { Assert.Equal(expected, Fuzzy.WeightedRatio(s1, s2)); }
public IEnumerator CompararDatos(HandRecord _leftHand, HandRecord _rightHand, float _tiempoEntreTirajes) { float tiempoTMp = _tiempoEntreTirajes / _leftHand.v_NumeroDeTirajes; bool[] isLeft = new bool[_leftHand.v_NumeroDeTirajes]; bool[] isRight = new bool[_rightHand.v_NumeroDeTirajes]; for (int i = 0; i < _leftHand.v_NumeroDeTirajes; i++) { //Debug.Log("> Tiraje" + i); if (v_ManoIzquierdaActiva && _leftHand.v_ManoActiva) { bool rot_Palma = _leftHand.v_RotacionPalma[i] == v_PosicionManoIzquierda; bool estadoThumb = _leftHand.v_EstadoThumb[i] == v_EstadoThumbIzquierdo; bool estadoIndex = _leftHand.v_EstadoIndex[i] == v_EstadoIndexIzquierdo; bool estadoMiddle = _leftHand.v_EstadoMiddle[i] == v_EstadoMiddleIzquierdo; bool estadoRing = _leftHand.v_EstadoRing[i] == v_EstadoRingIzquierdo; bool estadoPinky = _leftHand.v_EstadoPinky[i] == v_EstadoPinkyIzquierdo; bool dedosExtendidos = _leftHand.v_DedosExtendidos[i] == v_NumeroDeDedosActivosHIzquierda; //Posiciones bool[] posBonesIndex = new bool[3]; posBonesIndex[0] = Fuzzy.CompareVector(_leftHand.v_PosBonesIndex0[i], IndexI[0].transform.position); posBonesIndex[1] = Fuzzy.CompareVector(_leftHand.v_PosBonesIndex1[i], IndexI[1].transform.position); posBonesIndex[2] = Fuzzy.CompareVector(_leftHand.v_PosBonesIndex2[i], IndexI[2].transform.position); bool[] posBonesMiddle = new bool[3]; posBonesMiddle[0] = Fuzzy.CompareVector(_leftHand.v_PosBonesMiddle0[i], MiddleI[0].transform.position); posBonesMiddle[1] = Fuzzy.CompareVector(_leftHand.v_PosBonesMiddle1[i], MiddleI[1].transform.position); posBonesMiddle[2] = Fuzzy.CompareVector(_leftHand.v_PosBonesMiddle2[i], MiddleI[2].transform.position); bool[] posBonesRing = new bool[3]; posBonesRing[0] = Fuzzy.CompareVector(_leftHand.v_PosBonesRing0[i], RingI[0].transform.position); posBonesRing[1] = Fuzzy.CompareVector(_leftHand.v_PosBonesRing1[i], RingI[1].transform.position); posBonesRing[2] = Fuzzy.CompareVector(_leftHand.v_PosBonesRing2[i], RingI[2].transform.position); bool[] posBonesPinky = new bool[3]; posBonesPinky[0] = Fuzzy.CompareVector(_leftHand.v_PosBonesPinky0[i], PinkyI[0].transform.position); posBonesPinky[1] = Fuzzy.CompareVector(_leftHand.v_PosBonesPinky1[i], PinkyI[1].transform.position); posBonesPinky[2] = Fuzzy.CompareVector(_leftHand.v_PosBonesPinky2[i], PinkyI[2].transform.position); bool[] posBonesThumb = new bool[3]; posBonesThumb[0] = Fuzzy.CompareVector(_leftHand.v_PosBonesThumb0[i], ThumbI[0].transform.position); posBonesThumb[1] = Fuzzy.CompareVector(_leftHand.v_PosBonesThumb1[i], ThumbI[1].transform.position); posBonesThumb[2] = Fuzzy.CompareVector(_leftHand.v_PosBonesThumb2[i], ThumbI[2].transform.position); //Rotaciones bool[] rotBonesIndex = new bool[3]; rotBonesIndex[0] = Fuzzy.CompareVector(_leftHand.v_RotBonesIndex0[i], IndexI[0].transform.rotation.eulerAngles); rotBonesIndex[1] = Fuzzy.CompareVector(_leftHand.v_RotBonesIndex1[i], IndexI[1].transform.rotation.eulerAngles); rotBonesIndex[2] = Fuzzy.CompareVector(_leftHand.v_RotBonesIndex2[i], IndexI[2].transform.rotation.eulerAngles); bool[] rotBonesMiddle = new bool[3]; rotBonesMiddle[0] = Fuzzy.CompareVector(_leftHand.v_RotBonesMiddle0[i], MiddleI[0].transform.rotation.eulerAngles); rotBonesMiddle[1] = Fuzzy.CompareVector(_leftHand.v_RotBonesMiddle1[i], MiddleI[1].transform.rotation.eulerAngles); rotBonesMiddle[2] = Fuzzy.CompareVector(_leftHand.v_RotBonesMiddle2[i], MiddleI[2].transform.rotation.eulerAngles); bool[] rotBonesRing = new bool[3]; rotBonesRing[0] = Fuzzy.CompareVector(_leftHand.v_RotBonesRing0[i], RingI[0].transform.rotation.eulerAngles); rotBonesRing[1] = Fuzzy.CompareVector(_leftHand.v_RotBonesRing1[i], RingI[1].transform.rotation.eulerAngles); rotBonesRing[2] = Fuzzy.CompareVector(_leftHand.v_RotBonesRing2[i], RingI[2].transform.rotation.eulerAngles); bool[] rotBonesPinky = new bool[3]; rotBonesPinky[0] = Fuzzy.CompareVector(_leftHand.v_RotBonesPinky0[i], PinkyI[0].transform.rotation.eulerAngles); rotBonesPinky[1] = Fuzzy.CompareVector(_leftHand.v_RotBonesPinky1[i], PinkyI[1].transform.rotation.eulerAngles); rotBonesPinky[2] = Fuzzy.CompareVector(_leftHand.v_RotBonesPinky2[i], PinkyI[2].transform.rotation.eulerAngles); bool[] rotBonesThumb = new bool[3]; rotBonesThumb[0] = Fuzzy.CompareVector(_leftHand.v_RotBonesThumb0[i], ThumbI[0].transform.rotation.eulerAngles); rotBonesThumb[1] = Fuzzy.CompareVector(_leftHand.v_RotBonesThumb1[i], ThumbI[1].transform.rotation.eulerAngles); rotBonesThumb[2] = Fuzzy.CompareVector(_leftHand.v_RotBonesThumb2[i], ThumbI[2].transform.rotation.eulerAngles); bool posBrazo = Fuzzy.CompareVector(_leftHand.v_PosBrazo[i], ForI.transform.position); bool rotBrazo = Fuzzy.CompareVector(_leftHand.v_RotBrazo[i], ForI.transform.rotation.eulerAngles); bool posPalma = Fuzzy.CompareVector(_leftHand.v_PosPalma[i], PalmI.transform.position); bool rotPalma = Fuzzy.CompareVector(_leftHand.v_RotPalma[i], PalmI.transform.rotation.eulerAngles); if (rot_Palma && estadoThumb && estadoIndex && estadoMiddle && estadoRing && estadoPinky) { if (posBonesIndex[0] && posBonesIndex[1] && posBonesIndex[2] && posBonesMiddle[0] && posBonesMiddle[1] && posBonesMiddle[2] && posBonesRing[0] && posBonesRing[1] && posBonesRing[2] && posBonesPinky[0] && posBonesPinky[1] && posBonesPinky[2] && posBonesThumb[0] && posBonesThumb[1] && posBonesThumb[2] && rotBonesIndex[0] && rotBonesIndex[1] && rotBonesIndex[2] && rotBonesMiddle[0] && rotBonesMiddle[1] && rotBonesMiddle[2] && rotBonesRing[0] && rotBonesRing[1] && rotBonesRing[2] && rotBonesPinky[0] && rotBonesPinky[1] && rotBonesPinky[2] && rotBonesThumb[0] && rotBonesThumb[1] && rotBonesThumb[2]) { if (posBrazo && rotBrazo && posPalma && rotPalma) { isLeft[i] = true; } } } } if (v_ManoDerechaActiva && _rightHand.v_ManoActiva) { bool rot_Palma = _rightHand.v_RotacionPalma[i] == v_PosicionManoDerecha; bool estadoThumb = _rightHand.v_EstadoThumb[i] == v_EstadoThumbDerecho; bool estadoIndex = _rightHand.v_EstadoIndex[i] == v_EstadoIndexDerecho; bool estadoMiddle = _rightHand.v_EstadoMiddle[i] == v_EstadoMiddleDerecho; bool estadoRing = _rightHand.v_EstadoRing[i] == v_EstadoRingDerecho; bool estadoPinky = _rightHand.v_EstadoPinky[i] == v_EstadoPinkyDerecho; Debug.Log("Rot palma: " + _rightHand.v_RotacionPalma[i] + " - " + v_PosicionManoDerecha + "\n" + "Estado Thumb: " + _rightHand.v_EstadoThumb[i] + " - " + v_EstadoThumbDerecho + "\n" + "Estado Index: " + _rightHand.v_EstadoIndex[i] + " - " + v_EstadoIndexDerecho + "\n" + "Estado Middle: " + _rightHand.v_EstadoMiddle[i] + " - " + v_EstadoMiddleDerecho + "\n" + "Estado Ring: " + _rightHand.v_EstadoRing[i] + " - " + v_EstadoPinkyDerecho + "\n" + "Estado Pinky: " + _rightHand.v_EstadoPinky[i] + " - " + v_EstadoPinkyDerecho + "\n"); bool dedosExtendidos = Fuzzy.CompareInt(_rightHand.v_DedosExtendidos[i], v_NumeroDeDedosActivosHDerecha); //Posiciones #region POSICIONES bool[] posBonesIndex = new bool[3]; posBonesIndex[0] = Fuzzy.CompareVector(_rightHand.v_PosBonesIndex0[i], IndexD[0].transform.position); posBonesIndex[1] = Fuzzy.CompareVector(_rightHand.v_PosBonesIndex1[i], IndexD[1].transform.position); posBonesIndex[2] = Fuzzy.CompareVector(_rightHand.v_PosBonesIndex2[i], IndexD[2].transform.position); bool[] posBonesMiddle = new bool[3]; posBonesMiddle[0] = Fuzzy.CompareVector(_rightHand.v_PosBonesMiddle0[i], MiddleD[0].transform.position); posBonesMiddle[1] = Fuzzy.CompareVector(_rightHand.v_PosBonesMiddle1[i], MiddleD[1].transform.position); posBonesMiddle[2] = Fuzzy.CompareVector(_rightHand.v_PosBonesMiddle2[i], MiddleD[2].transform.position); bool[] posBonesRing = new bool[3]; posBonesRing[0] = Fuzzy.CompareVector(_rightHand.v_PosBonesRing0[i], RingD[0].transform.position); posBonesRing[1] = Fuzzy.CompareVector(_rightHand.v_PosBonesRing1[i], RingD[1].transform.position); posBonesRing[2] = Fuzzy.CompareVector(_rightHand.v_PosBonesRing2[i], RingD[2].transform.position); bool[] posBonesPinky = new bool[3]; posBonesPinky[0] = Fuzzy.CompareVector(_rightHand.v_PosBonesPinky0[i], PinkyD[0].transform.position); posBonesPinky[1] = Fuzzy.CompareVector(_rightHand.v_PosBonesPinky1[i], PinkyD[1].transform.position); posBonesPinky[2] = Fuzzy.CompareVector(_rightHand.v_PosBonesPinky2[i], PinkyD[2].transform.position); bool[] posBonesThumb = new bool[3]; posBonesThumb[0] = Fuzzy.CompareVector(_rightHand.v_PosBonesThumb0[i], ThumbD[0].transform.position); posBonesThumb[1] = Fuzzy.CompareVector(_rightHand.v_PosBonesThumb1[i], ThumbD[1].transform.position); posBonesThumb[2] = Fuzzy.CompareVector(_rightHand.v_PosBonesThumb2[i], ThumbD[2].transform.position); #endregion //Rotaciones #region ROTACIONES bool[] rotBonesIndex = new bool[3]; rotBonesIndex[0] = Fuzzy.CompareVector(_rightHand.v_RotBonesIndex0[i], IndexD[0].transform.rotation.eulerAngles); rotBonesIndex[1] = Fuzzy.CompareVector(_rightHand.v_RotBonesIndex1[i], IndexD[1].transform.rotation.eulerAngles); rotBonesIndex[2] = Fuzzy.CompareVector(_rightHand.v_RotBonesIndex2[i], IndexD[2].transform.rotation.eulerAngles); bool[] rotBonesMiddle = new bool[3]; rotBonesMiddle[0] = Fuzzy.CompareVector(_rightHand.v_RotBonesMiddle0[i], MiddleD[0].transform.rotation.eulerAngles); rotBonesMiddle[1] = Fuzzy.CompareVector(_rightHand.v_RotBonesMiddle1[i], MiddleD[1].transform.rotation.eulerAngles); rotBonesMiddle[2] = Fuzzy.CompareVector(_rightHand.v_RotBonesMiddle2[i], MiddleD[2].transform.rotation.eulerAngles); bool[] rotBonesRing = new bool[3]; rotBonesRing[0] = Fuzzy.CompareVector(_rightHand.v_RotBonesRing0[i], RingD[0].transform.rotation.eulerAngles); rotBonesRing[1] = Fuzzy.CompareVector(_rightHand.v_RotBonesRing1[i], RingD[1].transform.rotation.eulerAngles); rotBonesRing[2] = Fuzzy.CompareVector(_rightHand.v_RotBonesRing2[i], RingD[2].transform.rotation.eulerAngles); bool[] rotBonesPinky = new bool[3]; rotBonesPinky[0] = Fuzzy.CompareVector(_rightHand.v_RotBonesPinky0[i], PinkyD[0].transform.rotation.eulerAngles); rotBonesPinky[1] = Fuzzy.CompareVector(_rightHand.v_RotBonesPinky1[i], PinkyD[1].transform.rotation.eulerAngles); rotBonesPinky[2] = Fuzzy.CompareVector(_rightHand.v_RotBonesPinky2[i], PinkyD[2].transform.rotation.eulerAngles); bool[] rotBonesThumb = new bool[3]; rotBonesThumb[0] = Fuzzy.CompareVector(_rightHand.v_RotBonesThumb0[i], ThumbD[0].transform.rotation.eulerAngles); rotBonesThumb[1] = Fuzzy.CompareVector(_rightHand.v_RotBonesThumb1[i], ThumbD[1].transform.rotation.eulerAngles); rotBonesThumb[2] = Fuzzy.CompareVector(_rightHand.v_RotBonesThumb2[i], ThumbD[2].transform.rotation.eulerAngles); #endregion bool posBrazo = Fuzzy.CompareVector(_rightHand.v_PosBrazo[i], ForD.transform.position); bool rotBrazo = Fuzzy.CompareVector(_rightHand.v_RotBrazo[i], ForD.transform.rotation.eulerAngles); bool posPalma = Fuzzy.CompareVector(_rightHand.v_PosPalma[i], PalmD.transform.position); bool rotPalma = Fuzzy.CompareVector(_rightHand.v_RotPalma[i], PalmD.transform.rotation.eulerAngles); if (rot_Palma && estadoThumb && estadoIndex && estadoMiddle || estadoRing || estadoPinky) { if ( ( ((posBonesThumb[0] || posBonesThumb[1] || posBonesThumb[2]) && (posBonesIndex[0] || posBonesIndex[1] || posBonesIndex[2])) && ((posBonesMiddle[0] || posBonesMiddle[1] || posBonesMiddle[2]) || (posBonesRing[0] || posBonesRing[1] || posBonesRing[2]) || (posBonesPinky[0] || posBonesPinky[1] || posBonesPinky[2])) ) || ( ((rotBonesThumb[0] || rotBonesThumb[1] || rotBonesThumb[2]) && (rotBonesIndex[0] || rotBonesIndex[1] || rotBonesIndex[2])) && ((rotBonesMiddle[0] || rotBonesMiddle[1] || rotBonesMiddle[2]) || (rotBonesRing[0] || rotBonesRing[1] || rotBonesRing[2]) || (rotBonesPinky[0] || rotBonesPinky[1] || rotBonesPinky[2])) ) ) { Debug.Log("I got all pos and rot right!"); //isRight[i] = true; if ((posBrazo || rotBrazo) || (posPalma || rotPalma)) { Debug.Log("This part is tricku"); isRight[i] = true; } } } } yield return(new WaitForSeconds(tiempoTMp)); } //Si si coinciden, entonces activar if ((_leftHand.v_ManoActiva && Comparar(isLeft)) || (_rightHand.v_ManoActiva && Comparar(isRight))) { StartCoroutine(WaitToTurnPanelOff(matchFound)); FindObjectOfType <SCR_GameManager>().LoadNextGesture(); } }
public still(T stateName, Fuzzy controller, float minDuration) : base(stateName, controller, minDuration) { }
public bool IsOnGrid(Fuzzy x) { return x - Fuzzy.Round(x) == 0; }
public ActionResult StockPrediction(ViewModel obj) { var supplierName = User.Identity.Name; var context = new ATokoDb(); if (!string.IsNullOrEmpty(obj.ProductCode)) { //string productCode = ""; ViewBag.productName = context.Products.Where(o => o.ProductCode == obj.ProductCode).FirstOrDefault().ProductName; string querySales = string.Format("EXEC [dbo].[sp_GetSalesByProductCodeAndSupplierName] @productCode = '{0}', @supplierName = '{1}'", obj.ProductCode, supplierName); string queryStock = string.Format("EXEC [dbo].[sp_GetStockByProductCodeAndSupplierName] @productCode = '{0}', @supplierName = '{1}'", obj.ProductCode, supplierName); string queryOrder = string.Format("EXEC [dbo].[sp_GetProductInByProductCodeAndSupplierName] @productCode = '{0}', @supplierName = '{1}'", obj.ProductCode, supplierName); IEnumerable <FuzzyViewModel> listSalesByMonth = db.Database.SqlQuery <FuzzyViewModel>(querySales); IEnumerable <FuzzyViewModel> listStocksByMonth = db.Database.SqlQuery <FuzzyViewModel>(queryStock); IEnumerable <FuzzyViewModel> listOrderByMonth = db.Database.SqlQuery <FuzzyViewModel>(queryOrder); if (listOrderByMonth.Count() > 0 && listSalesByMonth.Count() > 0 && listStocksByMonth.Count() > 0) { if (listOrderByMonth.Count() != listSalesByMonth.Count()) { int count = listStocksByMonth.Count(); List <FuzzyViewModel> newList = new List <FuzzyViewModel>(); bool isSales = false; if (listOrderByMonth.Count() != count) { isSales = false; } else if (listSalesByMonth.Count() != count) { isSales = true; } if (isSales) { foreach (var item in listStocksByMonth) { if (listSalesByMonth.Where(o => o.Year == item.Year && o.Month == item.Month).Count() > 0) { newList.Add(listSalesByMonth.Where(o => o.Year == item.Year && o.Month == item.Month).FirstOrDefault()); } else { newList.Add(new FuzzyViewModel { Month = item.Month, Year = item.Year, ProductCode = item.ProductCode, Qty = 0 }); } } listSalesByMonth = newList; } else { foreach (var item in listStocksByMonth) { if (listOrderByMonth.Where(o => o.Year == item.Year && o.Month == item.Month).Count() > 0) { newList.Add(listOrderByMonth.Where(o => o.Year == item.Year && o.Month == item.Month).FirstOrDefault()); } else { newList.Add(new FuzzyViewModel { Month = item.Month, Year = item.Year, ProductCode = item.ProductCode, Qty = 0 }); } } listOrderByMonth = newList; } } int maxSales = listSalesByMonth.Max(o => o.Qty); int minSales = listSalesByMonth.Min(o => o.Qty); var lastSalesObj = listSalesByMonth.OrderByDescending(o => o.Year).ThenByDescending(o => o.Month).FirstOrDefault(); int lastSales = lastSalesObj.Qty; int maxStock = listStocksByMonth.Max(o => o.Qty); int minStock = listStocksByMonth.Min(o => o.Qty); var lastStockObj = listStocksByMonth.OrderByDescending(o => o.Year).ThenByDescending(o => o.Month).FirstOrDefault(); int lastStock = lastStockObj.Qty; int maxOrder = listOrderByMonth.Max(o => o.Qty); int minOrder = listOrderByMonth.Min(o => o.Qty); var lastOrderObj = listOrderByMonth.OrderByDescending(o => o.Year).ThenByDescending(o => o.Month).FirstOrDefault(); int lastOrder = lastOrderObj.Qty; var sales = new Fuzzy(); sales.MaxNumber = maxSales; sales.MinNumber = minSales; sales.Input = lastSales; sales.CalculateLinearUp(); sales.CalculateLinearDown(); var stock = new Fuzzy(); stock.MaxNumber = maxStock; stock.MinNumber = minStock; stock.Input = lastStock; stock.CalculateLinearUp(); stock.CalculateLinearDown(); var order = new Fuzzy(); order.MaxNumber = maxOrder; order.MinNumber = minOrder; order.Input = lastOrder; order.CalculateLinearUp(); order.CalculateLinearDown(); var ruleSet = new Fuzzy(); var item1 = new Fuzzy(); item1.InputSales = sales.ResultLinearDown; item1.InputStock = stock.ResultLinearUp; ruleSet.Rule1 = item1.ImplicationFunction(); var item2 = new Fuzzy(); item2.InputSales = sales.ResultLinearDown; item2.InputStock = stock.ResultLinearDown; ruleSet.Rule2 = item2.ImplicationFunction(); var item3 = new Fuzzy(); item3.InputSales = sales.ResultLinearUp; item3.InputStock = stock.ResultLinearUp; ruleSet.Rule3 = item3.ImplicationFunction(); var item4 = new Fuzzy(); item4.InputSales = sales.ResultLinearUp; item4.InputStock = stock.ResultLinearDown; ruleSet.Rule4 = item4.ImplicationFunction(); ruleSet.RuleComposition(); if (ruleSet.DownResult < ruleSet.UpResult) { ruleSet.OrderStatus = 1; // Up } else if (ruleSet.DownResult > ruleSet.UpResult) { ruleSet.OrderStatus = 2; // Down } else { ruleSet.OrderStatus = 1; } //else if(ruleSet.UpResult == ruleSet.DownResult) //{ // ruleSet.OrderStatus = 3; //} var membershipFunction = new Fuzzy(); if (ruleSet.OrderStatus == 1) // Up { membershipFunction.OrderMax = (order.Range * ruleSet.UpResult) + order.MinNumber; membershipFunction.OrderMin = (order.Range * ruleSet.DownResult) + order.MinNumber; membershipFunction.OrderStatus = 1; } else if (ruleSet.OrderStatus == 2) // Down { membershipFunction.OrderMax = (order.Range * ruleSet.UpResult) + order.MaxNumber; membershipFunction.OrderMin = (order.Range * ruleSet.DownResult) + order.MaxNumber; membershipFunction.OrderStatus = 2; } //else if (ruleSet.OrderStatus == 3) //{ // membershipFunction.OrderMax = (order.Range * ruleSet.UpResult) + order.MaxNumber; // membershipFunction.OrderMin = (order.Range * ruleSet.DownResult) + order.MaxNumber; // membershipFunction.OrderStatus = 3; //} membershipFunction.MaxNumber = order.MaxNumber; membershipFunction.MinNumber = order.MinNumber; membershipFunction.UpResult = ruleSet.UpResult; membershipFunction.DownResult = ruleSet.DownResult; //ViewBag.Result = membershipFunction.Defuzzyfication(); var listSeries = new List <ReportFuzzyViewModel>(); var date = new DateTime(lastOrderObj.Year, lastOrderObj.Month, 1); var nextMonth = date.AddMonths(1); var listOrder = listOrderByMonth.OrderBy(o => o.Year).ThenBy(o => o.Month); var listSales = listSalesByMonth.OrderBy(o => o.Year).ThenBy(o => o.Month).ToList(); foreach (var item in listOrder) { listSeries.Add(new ReportFuzzyViewModel { Date = new DateTime(item.Year, item.Month, 1).ToString("MMM yy"), Quantity = item.Qty }); } listSeries.Add(new ReportFuzzyViewModel { Date = nextMonth.ToString("MMM yy"), Quantity = 0 }); var listResult = new List <ReportFuzzyViewModel>(); listResult.Add(new ReportFuzzyViewModel { Date = nextMonth.ToString("MMM yy"), Quantity = decimal.Round(membershipFunction.Defuzzyfication()) }); var arrSalesQty = "["; var arrOrderQty = "["; var arrOrderDate = "["; var arrOrderResult = "["; decimal lastSeries = 0; int indexLast = 0; for (int i = 0; i < listSeries.Count; i++) { var x = i + 1; if (x >= listSeries.Count) { indexLast = i - 1; lastSeries = listSeries[i - 1].Quantity; arrSalesQty = arrSalesQty + "null"; arrOrderQty = arrOrderQty + "null";//string.Format("{0}", listSeries[i].Quantity); arrOrderDate = arrOrderDate + string.Format("'{0}'", listSeries[i].Date); } else { arrSalesQty = arrSalesQty + string.Format("{0},", listSales[i].Qty); arrOrderQty = arrOrderQty + string.Format("{0},", listSeries[i].Quantity); arrOrderDate = arrOrderDate + string.Format("'{0}',", listSeries[i].Date); } } for (int i = 0; i < listSeries.Count; i++) { var x = i + 1; if (x >= listSeries.Count) { arrOrderResult = arrOrderResult + "{y:" + listResult[0].Quantity + ",marker: {enabled: true,states: {hover: {enabled: true}}}}";//string.Format("{0}", listResult[0].Quantity); } else if (i == indexLast) { arrOrderResult = arrOrderResult + "{y:" + lastSeries + ",marker: {enabled: false,states: {hover: {enabled: false}}}},"; } else { arrOrderResult = arrOrderResult + "null,"; } } //if (arrOrderQty.Length > 2) //{ // arrOrderQty = arrOrderQty.Remove(arrOrderQty.Length - 1); //} //if (arrOrderDate.Length > 2) //{ // arrOrderDate = arrOrderDate.Remove(arrOrderDate.Length - 1); //} arrSalesQty = arrSalesQty + "]"; arrOrderQty = arrOrderQty + "]"; arrOrderDate = arrOrderDate + "]"; arrOrderResult = arrOrderResult + "]"; ViewBag.arrSalesQty = arrSalesQty; ViewBag.arrOrderQty = arrOrderQty; ViewBag.arrOrderDate = arrOrderDate; ViewBag.arrOrderResult = arrOrderResult; ViewBag.Result = "According to the calculations, the number of products (" + ViewBag.productName + ") should be ordered on the next month (" + nextMonth.ToString("MMM yy") + ") is about (" + decimal.Round(membershipFunction.Defuzzyfication()) + ") pieces"; } else { ViewBag.ErrMsg = "Insufficient data, cannot calculating stock prediction"; } } else { ViewBag.ErrMsg = "Please select a product"; } List <Product> list = new List <Product>(); Supplier ret = context.Suppliers.Where(o => o.SupplierName == supplierName).FirstOrDefault(); if (ret != null) { list = context.Products.Where(o => o.SupplierID == ret.SupplierID).ToList(); } else if (User.IsInRole("admin") || User.IsInRole("sales")) { list = context.Products.ToList(); } List <Product> listproduct = list; foreach (var item in listproduct) { item.ProductName = item.ProductCode + " - " + item.ProductName; } obj.listProduct = listproduct; return(View(obj)); }
public bool SolveDirection(Direction direction) { var distance = new Fuzzy(0.0); var position = startPosition; Log("----"); while (true) { Log("(X ; Y) = ({0} ; {1})", position.X, position.Y); Log("(dX ; dY) = ({0} ; {1})", direction.Dx, direction.Dy); distance += position.MoveAlong(direction, step, out position); if (distance > maxDistance) { Log("Max distance reached"); return false; } if (position.Equals(startPosition)) { Log("Start position reached !!!"); return true; } bool reflectionOnX, reflectionOnY; var xOnGrid = Fuzzy.Floor(position.X); var yOnGrid = Fuzzy.Floor(position.Y); Log("(X ; Y) = ({0} ; {1})", position.X, position.Y); var isOnHorizontalGrid = position.Y == yOnGrid; var isOnVerticalGrid = position.X == xOnGrid; Log("isOnHorizontalGrid = {0}", isOnHorizontalGrid); Log("isOnVerticalGrid = {0}", isOnVerticalGrid); if (isOnHorizontalGrid && isOnVerticalGrid) { var mirrorOnUpperLeft = IsMirrorAt(position.X - step, position.Y - step); var mirrorOnUpperRight = IsMirrorAt(position.X + step, position.Y - step); var mirrorOnLowerLeft = IsMirrorAt(position.X - step, position.Y + step); var mirrorOnLowerRight = IsMirrorAt(position.X + step, position.Y + step); // we can't possibly be in the middle of 4 mirrors Debug.Assert(!(mirrorOnUpperLeft&&mirrorOnUpperRight&&mirrorOnLowerLeft&&mirrorOnLowerRight)); reflectionOnX = mirrorOnUpperLeft && mirrorOnLowerLeft || mirrorOnUpperRight && mirrorOnLowerRight; reflectionOnY = mirrorOnUpperLeft && mirrorOnUpperRight || mirrorOnLowerLeft && mirrorOnLowerRight; } else if (isOnHorizontalGrid) { var mirrorAbove = IsMirrorAt(position.X, position.Y - step); var mirrorBelow = IsMirrorAt(position.X, position.Y + step); reflectionOnY = mirrorAbove || mirrorBelow; reflectionOnX = false; } else if (isOnVerticalGrid) { var mirrorOnLeft = IsMirrorAt(position.X - step, position.Y); var mirrorOnRight = IsMirrorAt(position.X + step, position.Y); reflectionOnX = mirrorOnLeft || mirrorOnRight; reflectionOnY = false; } else if (IsMirrorAt(position.X, position.Y)) { Log("ray is destroyed"); return false; } else { reflectionOnY = false; reflectionOnX = false; } if (position.X <= 1 || position.X >= grid.GetLength(0) - 1) Debug.Assert(reflectionOnX); if (position.Y <= 1 || position.Y >= grid.GetLength(1) - 1) Debug.Assert(reflectionOnY); if (reflectionOnX) Log("reflection on Y"); if (reflectionOnY) Log("reflection on Y"); direction = new Direction( direction.Dx * (reflectionOnX ? -1 : 1), direction.Dy * (reflectionOnY ? -1 : 1)); } }
public static Fuzzy ToFuzzy(this bool value) => Fuzzy.Create(value);
public Position(Fuzzy x, Fuzzy y) { this.x = x; this.y = y; }
public Event(EventType type, Fuzzy time, int car1, int car2) : this() { Type = type; Time = time; Car1 = car1; Car2 = car2; }