public static Player GetPlayer(ResultPosition resultPosition) { Player player = null; if (resultPosition == ResultPosition.Winner) { for (int i = 0; i < 7; i++) { if (global::MatchEvaluation.inst.PlResult[i].resultPosition == ResultPosition.Winner) { player = PlayerMan.inst.GetPlObj(i); break; } } } else if (resultPosition == ResultPosition.Loser) { for (int i = 0; i < 7; i++) { if (global::MatchEvaluation.inst.PlResult[i].resultPosition == ResultPosition.Loser) { player = PlayerMan.inst.GetPlObj(i); break; } } } return(player); }
private void OnEnable() { meshFilters = new MeshFilter[0]; resultHolder = null; resultPosition = ResultPosition.CenterOfMass; settings = new MeshBasedBakeSettings(); serializedObject = new SerializedObject(this); }
public Dictionary <long, ResultPosition> ProcessEvent( int EventID, Dictionary <string, Dictionary <int, Dictionary <long, Tuple <double, uint, List <float> > > > > EventOccurrenceDRs, bool ShouldAllocate, int MaxConcurrencyContracts, params long[] ContractIDs) { ConcurrentDictionary <long, ResultPosition> ContractIdToResultMap = new ConcurrentDictionary <long, ResultPosition>(); #region Recursion List <long> IndependentContractIDs = GetIndependentContractIDs(ContractIDs); //int LevelConcurrency = Environment.ProcessorCount - 1; //int BatchSize = 100; //int TotalSize = IndependentContractIDs.Count; //Parallel.For(0, ((TotalSize / BatchSize) + 1), new ParallelOptions { MaxDegreeOfParallelism = MaxConcurrencyContracts }, i => Parallel.ForEach(IndependentContractIDs, new ParallelOptions { MaxDegreeOfParallelism = MaxConcurrencyContracts }, id => //UNCOMMENT FOR CONTRACTS IN PARALLEL //foreach (long id in IndependentContractIDs) // UNCOMMENT FOR CONTRACTS IN SEQUENCE { //int BatchUpper = ((i + 1) * BatchSize); //for (int j = i * BatchSize; j < BatchUpper && j < TotalSize; j++) //{ //long id = IndependentContractIDs[j]; var ced = GetContractData(id); if (!(ced.state == ProcessState.ContractGraphBuilt || ced.state == ProcessState.FMExecuted || ced.state == ProcessState.FMFailed)) { Console.WriteLine("Contract with ID : " + id + " is invalid and is not executable!"); //Logger.LogInfoFormatExt("Contract with ID : " + id + " is invalid and is not executable!"); return; } if (ced is PrimaryContractExposureData) { ced = new PrimaryContractExposureData((PrimaryContractExposureData)ced); } else { ced = new TreatyContractExposureData((TreatyContractExposureData)ced); } ResultPosition Result = ProcessEventRecursor(EventID, ContractIdToResultMap, EventOccurrenceDRs, ced, ShouldAllocate); if (null != Result) { ContractIdToResultMap.TryAdd(id, Result); } //} } );//UNCOMMENT FOR CONTRACTS IN PARALLEL return(ContractIdToResultMap.ToDictionary(kvp => kvp.Key, kvp => kvp.Value)); #endregion }
public static int CompareRank(Player winner, Player loser, ResultPosition position) { RankEnum winnerRank = winner.WresParam.wrestlerRank; RankEnum loserRank = loser.WresParam.wrestlerRank; int difference = loserRank - winnerRank; if (position == ResultPosition.Winner) { if (difference >= 4) { return(2); } else { if (difference >= 2) { return(1); } else { return(0); } } } else { if (difference >= 4) { return(-2); } else { if (difference >= 2) { return(-1); } else { return(0); } } } }
private ResultPosition ProcessEventRecursor( int EventID, ConcurrentDictionary <long, ResultPosition> ContractIdToResultMap, Dictionary <string, Dictionary <int, Dictionary <long, Tuple <double, uint, List <float> > > > > EventOccurrenceDRs, ContractExposureData node, bool ShouldAllocate) { if (node is TreatyContractExposureData) { #region Recursion var childrenIDs = ((TreatyContractExposureData)node).ChildContractExposureIDs; foreach (long id in childrenIDs) { var ced = GetContractData(id); if (ced is PrimaryContractExposureData) { ced = new PrimaryContractExposureData((PrimaryContractExposureData)ced); } else { ced = new TreatyContractExposureData((TreatyContractExposureData)ced); } ResultPosition Result = ProcessEventRecursor(EventID, ContractIdToResultMap, EventOccurrenceDRs, ced, true); if (null != Result) { ContractIdToResultMap.TryAdd(id, Result); } } #endregion } if ((node.state == ProcessState.ContractGraphBuilt || node.state == ProcessState.FMExecuted || node.state == ProcessState.FMFailed)) { return(node.ExecuteFM(EventOccurrenceDRs, ShouldAllocate, ContractIdToResultMap.ToDictionary(kvp => kvp.Key, kvp => kvp.Value))); } return(null); }
protected ResultPosition ExecuteTreaty(SortedDictionary <DateTime, double> InputSubjectPosition, Dictionary <SimpleExpression <SymbolicValue>, double> Bindings, bool Allocate) { // Execute and return (and, optionally, allocate) double Payout = _CoverGraph.Execute(InputSubjectPosition.Values.Sum(), Bindings, Allocate); ResultPosition _ResultPosition = new ResultPosition { PayOut = Payout }; _ResultPosition.TimeAllocation = new SortedDictionary <DateTime, double>(); var TotalInputSubjectLoss = InputSubjectPosition.Values.Sum(); foreach (DateTime dt in InputSubjectPosition.Keys) { _ResultPosition.TimeAllocation.Add(dt, _ResultPosition.PayOut * InputSubjectPosition[dt] / TotalInputSubjectLoss); } _ResultPosition.InputTimeSeries = InputSubjectPosition; return(_ResultPosition); }
public static String BuildTeamName(ResultPosition position, int index) { String name = ""; Player plObj = PlayerMan.inst.GetPlObj(index); if (!plObj) { return(""); } if (plObj.isSecond || plObj.isIntruder) { return(""); } if (MatchEvaluation.inst.PlResult[index].resultPosition == ResultPosition.Winner_Partner || MatchEvaluation.inst.PlResult[index].resultPosition == ResultPosition.Loser_Partner) { name += " & " + DataBase.GetWrestlerFullName(plObj.WresParam); } return(name); }
public static String GetTeamName(ResultPosition position) { String name = ""; if (position == ResultPosition.Winner) { Player winner = GetPlayer(ResultPosition.Winner); if (!winner) { L.D("No winner found"); return(""); } name = DataBase.GetWrestlerFullName(winner.WresParam); if (winner.PlIdx < 4) { for (int i = 0; i < 4; i++) { name += BuildTeamName(ResultPosition.Winner_Partner, i); } if (teamNames[0] != String.Empty) { name = teamNames[0] + " (" + name + ")"; } } else { for (int i = 4; i < 8; i++) { name += BuildTeamName(ResultPosition.Winner_Partner, i); } if (teamNames[1] != String.Empty) { name = teamNames[1] + " (" + name + ")"; } } } else if (position == ResultPosition.Loser) { Player loser = GetPlayer(ResultPosition.Loser); if (!loser) { L.D("No loser found"); return(""); } name = DataBase.GetWrestlerFullName(loser.WresParam); if (loser.PlIdx < 4) { for (int i = 0; i < 4; i++) { name += BuildTeamName(ResultPosition.Loser_Partner, i); } if (teamNames[0] != String.Empty) { name = teamNames[0] + " (" + name + ")"; } } else { for (int i = 4; i < 8; i++) { name += BuildTeamName(ResultPosition.Loser_Partner, i); } if (teamNames[1] != String.Empty) { name = teamNames[1] + " (" + name + ")"; } } } else if (position == ResultPosition.Draw) { for (int i = 0; i < 4; i++) { Player player = PlayerMan.inst.GetPlObj(i); if (player) { if (!player.isIntruder && !player.isSecond) { if (i == 0) { name = DataBase.GetWrestlerFullName(player.WresParam); } else { name += ", " + DataBase.GetWrestlerFullName(player.WresParam); } } } } if (teamNames[0] != String.Empty) { name = teamNames[0] + "(" + name + ")"; } String blueTeam = name; name += ""; for (int i = 4; i < 8; i++) { Player player = PlayerMan.inst.GetPlObj(i); if (player) { if (!player.isIntruder && !player.isSecond) { if (i == 4) { name = DataBase.GetWrestlerFullName(player.WresParam); } else { name += ", " + DataBase.GetWrestlerFullName(player.WresParam); } } } } if (teamNames[1] != String.Empty) { name = teamNames[1] + " (" + name + ")"; } string redTeam = name; name = blueTeam + " & " + redTeam; } return(name); }
/// <summary> /// The order of executions and flow of data manifest in this method is fundamental to the correct execution of CDL. /// </summary> /// <param name="Schedule"></param> /// <param name="CoverageIdGULossMap"></param> protected ResultPosition ExecutePrimary(Dictionary <string, HashSet <long> > Schedule, Dictionary <long, RiskItemCharacteristicIDAttributes> ExposureIDAttributeMap, GULoss _GULoss, bool ShouldAllocate) { #region 1. Compute InputTimeSeries & ExposureIDGULossMap SortedDictionary <DateTime, double> _InputTimeSeries = _GULoss.InputTimeSeries; Dictionary <long, Loss> FlattenedGULosses = _GULoss.FlattenedGULosses; //SortedDictionary<DateTime, double> _InputTimeSeries = new SortedDictionary<DateTime, double>(); //foreach (var KVPByTimestamp in ExposureIDGULossMap) //{ // foreach (var KVPByExposureID in KVPByTimestamp.Value.GUByCOLByTime.Values) // { // foreach (var KVPByExposureIDByDateTime in KVPByExposureID) // { // if (!_InputTimeSeries.ContainsKey(KVPByExposureIDByDateTime.Key)) // _InputTimeSeries.Add(KVPByExposureIDByDateTime.Key, KVPByExposureIDByDateTime.Value); // else // _InputTimeSeries[KVPByExposureIDByDateTime.Key] += KVPByExposureIDByDateTime.Value; // } // } //} #endregion #region 1.5 Compute (true) GU Loss By RITE and RiskItem Dictionary <long, Dictionary <string, double> > _GULossByExposure = _GULoss.GULossByExposure; Dictionary <long, Dictionary <string, double> > _GULossByRiskItem = _GULoss.GULossByRiskItem; double _TotalGULoss = _GULoss.TotalGULoss; //double TotalGULoss = 0.0; //Dictionary<long, Dictionary<string, double>> _GULossByRITE = new Dictionary<long, Dictionary<string, double>>(); //Dictionary<long, Dictionary<string, double>> _GULossByRiskItem = new Dictionary<long, Dictionary<string, double>>(); //foreach (KeyValuePair<long, Loss> LossesPerRITEKVP in FlattenedGULosses) //{ // long RITEId = (ExposureIDAttributeMap[LossesPerRITEKVP.Key].OriginalRITECharacteristicId != null) ? // (long)ExposureIDAttributeMap[LossesPerRITEKVP.Key].OriginalRITECharacteristicId : // LossesPerRITEKVP.Key; // if (!_GULossByRITE.ContainsKey(RITEId)) // _GULossByRITE.Add(RITEId, new Dictionary<string, double>()); // long RiskItemID = (ExposureIDAttributeMap[LossesPerRITEKVP.Key].OriginalRITExposureId != null) ? // (long)ExposureIDAttributeMap[LossesPerRITEKVP.Key].OriginalRITExposureId : // ExposureIDAttributeMap[LossesPerRITEKVP.Key].RITExposureId; // if (!_GULossByRiskItem.ContainsKey(RiskItemID)) // _GULossByRiskItem.Add(RiskItemID, new Dictionary<string, double>()); // foreach (KeyValuePair<SymbolicValue, List<double>> LossPerRITEPerCOLKVP in LossesPerRITEKVP.Value.AmountByCOL) // { // double TotalLossesPerRITEPerCOL // = LossesPerRITEKVP.Value[LossPerRITEPerCOLKVP.Key]; // if (!_GULossByRITE[RITEId].ContainsKey(LossPerRITEPerCOLKVP.Key.ToString())) // _GULossByRITE[RITEId].Add(LossPerRITEPerCOLKVP.Key.ToString(), TotalLossesPerRITEPerCOL); // else // _GULossByRITE[RITEId][LossPerRITEPerCOLKVP.Key.ToString()] += TotalLossesPerRITEPerCOL; // if (!_GULossByRiskItem[RiskItemID].ContainsKey(LossPerRITEPerCOLKVP.Key.ToString())) // _GULossByRiskItem[RiskItemID].Add(LossPerRITEPerCOLKVP.Key.ToString(), TotalLossesPerRITEPerCOL); // else // _GULossByRiskItem[RiskItemID][LossPerRITEPerCOLKVP.Key.ToString()] = // _GULossByRiskItem[RiskItemID][LossPerRITEPerCOLKVP.Key.ToString()] // + // TotalLossesPerRITEPerCOL; // TotalGULoss += TotalLossesPerRITEPerCOL; // } //} #region GU Loss == 0 OPTIMIZATION //if (TotalGULoss < 5.0) //{ // return new ResultPosition // { // TotalGULoss = TotalGULoss, // GULossByRITE = new Dictionary<long,Dictionary<string,double>>(), // GULossByRiskItem = new Dictionary<long,Dictionary<string,double>>(), // PayOut = 0.0, // RITEAllocation = new Dictionary<long,Dictionary<string,double>>(), // RiskItemAllocation = new Dictionary<long, Dictionary<string, double>>(), // TimeAllocation = new SortedDictionary<DateTime,double>(), // InputTimeSeries = _InputTimeSeries // }; //} #endregion #endregion #region VERIFY UNNECESSARY : 1. Bindings var Bindings = new Dictionary <SimpleExpression <SymbolicValue>, double>(); //// bind subjectvar //if (TheContract.ContractSubject is RMS.ContractObjectModel.Subject) //{ // RMS.ContractObjectModel.Subject contractSubject = TheContract.ContractSubject as RMS.ContractObjectModel.Subject; // Dictionary<SymbolicValue, Dictionary<int, Tuple<HashSet<long>, HashSet<long>>>> ContractSubjectComponents2 = // contractSubject.GetComponents(); // double SubjectLoss = 0.0; // foreach (var Component2COL in ContractSubjectComponents2) // { // foreach (var Component2ResolvedExposureType in Component2COL.Value) // { // //HashSet<long> Component2RITEIds = new HashSet<long>(); // //foreach (long RITEId in ContractSubjectComponents2[Component2COL][Component2ResolvedExposureType].Item1) // // Component2RITEIds.Add(RITEId); // foreach (long Component2RITEId in Component2ResolvedExposureType.Value.Item1) // { // if (ExposureIDGULossMap.ContainsKey(Component2RITEId) && ExposureIDGULossMap[Component2RITEId].AmountByCOL.ContainsKey(Component2COL.Key)) // SubjectLoss += ExposureIDGULossMap[Component2RITEId].AmountByCOL[Component2COL.Key].Sum(); // } // } // } // Bindings.Add(new SymbolicExpression("Subject"), SubjectLoss); //} #endregion #region 2. Get RCVAffected and RCVCovered for all cover and term subjects Dictionary <SubjectPosition, Tuple <double, double> > RCVCoveredAndAffectedBySubjectForCovers = new Dictionary <SubjectPosition, Tuple <double, double> >(); Dictionary <TermNode, Tuple <double, double> > RCVCoveredAndAffectedBySubjectForTerms = new Dictionary <TermNode, Tuple <double, double> >(); foreach (CoverNode _CoverNode in _CoverGraph) { if (((Subject)_CoverNode.GetContent().GetSubject()).IsDerived()) { continue; } if (!RCVCoveredAndAffectedBySubjectForCovers.ContainsKey(_CoverNode.GetSubject())) { RCVCoveredAndAffectedBySubjectForCovers.Add(_CoverNode.GetSubject(), GetRCVCoveredAndAffected((Subject)_CoverNode.GetSubject(), Schedule, ExposureIDAttributeMap, FlattenedGULosses)); } } foreach (TermNode _TermNode in _TermGraph) { if (!RCVCoveredAndAffectedBySubjectForTerms.ContainsKey(_TermNode)) { RCVCoveredAndAffectedBySubjectForTerms.Add(_TermNode, GetRCVCoveredAndAffected(_TermNode.GetSubject(), Schedule, ExposureIDAttributeMap, FlattenedGULosses)); } } #endregion #region 3. Filter exposed RITEs (i.e. RITEs relevant to subject) FlattenedGULosses = _CoverGraph.FilterExposedExposureIDs(Schedule, ExposureIDAttributeMap, FlattenedGULosses); #endregion #region 4. GO THROUGH COVER LEAF NODES & MARK AS MULTI-BLDG PER RISK & RESET CanUseTermRootsForCoverLeafSubjectExposures, IF NECESSARY _CoverGraph.DetectMultiBldgPerRiskForCoverLeafs(FlattenedGULosses, ExposureIDAttributeMap); #endregion #region 5. ShouldActuallyAllocateAnyway? bool ShouldActuallyAllocateAnyway = ShouldAllocate || _TermGraph.IsOverlapping || !_CoverGraph.CanUseTermRootsForCoverLeafSubjectExposures; #endregion #region 6. Execute terms (and, optionally, or, if necessary, allocate) _TermGraph.Execute(Schedule, ExposureIDAttributeMap, FlattenedGULosses, RCVCoveredAndAffectedBySubjectForTerms, Bindings, ShouldActuallyAllocateAnyway); #endregion #region 7. Create subject exposure map for covers if (ShouldActuallyAllocateAnyway) { _CoverGraph.CreateSubjectExposureMapForLeafNodes(Schedule, FlattenedGULosses, ExposureIDAttributeMap); } #endregion #region 8. Execute (and, optionally, or, if necessary, allocate) double Payout = _CoverGraph.Execute_(_TermGraph, FlattenedGULosses, ExposureIDAttributeMap, RCVCoveredAndAffectedBySubjectForCovers, Bindings, ShouldActuallyAllocateAnyway); #endregion ResultPosition _ResultPosition = new ResultPosition { TotalGULoss = _TotalGULoss, GULossByRITE = _GULossByExposure, GULossByRiskItem = _GULossByRiskItem, PayOut = Payout, RITEAllocation = GetRITEAllocation(ExposureIDAttributeMap), RiskItemAllocation = GetRiskItemAllocation(ExposureIDAttributeMap), TimeAllocation = CalculatePayoutTimeSeries(Payout, _InputTimeSeries, ExposureIDAttributeMap), InputTimeSeries = _InputTimeSeries }; FlattenedGULosses = null; _GULoss = null; return(_ResultPosition); }
public CustomWebResult(string title = "", string content = "", ResultState resultState = NetCoreStack.Mvc.ResultState.Success, ResultPosition position = ResultPosition.TopFullWidth, int duration = 5000, List <ModelValidationResult> validations = null, string redirectUrl = null, bool resetForm = true) : base(title, content, resultState, position, duration, validations, redirectUrl, resetForm) { RedirectUrl = redirectUrl; if (title == Globals.Prefix || String.IsNullOrWhiteSpace(title)) { switch (resultState) { case NetCoreStack.Mvc.ResultState.Error: title = "Hata!"; break; case NetCoreStack.Mvc.ResultState.Info: title = "Bilgilendirme"; break; case NetCoreStack.Mvc.ResultState.Success: title = "Bilgilendirme"; break; case NetCoreStack.Mvc.ResultState.Warning: title = "Uyarı!"; break; } } Title = title; }