Example #1
0
        public new Tuple<int, int, int> Solve()
        {
            Tuple<int,int,int> results = new Tuple<int, int, int>(0,0,0);

            do
            {  // eliminated, solved, rounds
                Tuple<int,int,int> progress = new Tuple<int, int, int>(0,0,0);

                progress = progress.Add(base.Solve());

                if(base.IsSolved())
                {
                    results = results.Add(progress);
                    break;
                }

                progress = progress.Add(SolveModerate());

                if(progress.Item1==0 && progress.Item2==0)
                {
                    results = results.Add(progress);
                    break;
                }

                results = results.Add(progress);
            }
            while(!base.IsSolved());

            return results;
        }
Example #2
0
	public static void Main() {
        var test = new Tuple<int, Test.Tester>();
        test.Add(Test.Tester.Blue);
	}
			private void SelfTest()
			{
				for (int d1 = 0; d1 < this.dimensions.Length - 1; d1++)
				{
					for (int d2 = d1 + 1; d2 < this.dimensions.Length; d2++)
					{
						for (int f1 = 0; f1 < this.dimensions[d1]; f1++)
						{
							for (int f2 = 0; f2 < this.dimensions[d2]; f2++)
							{
								Tuple tuple = new Tuple();
								tuple.Add(new FeatureInfo(d1, f1));
								tuple.Add(new FeatureInfo(d2, f2));

								if (!this.testCases.IsTupleCovered(tuple))
								{
									throw new ApplicationException("PairwiseStrategy self-test failed : Not all pairs are covered!");
								}
							}
						}
					}
				}
			}
			private void ExtendTupleSet(int dimension, int feature)
			{
				// If tuples for [dimension][feature] already exists, it's no needs to add more tuples.
				if (this.uncoveredTuples[dimension][feature].Count > 0)
				{
					return;
				}

				// If maximum tuple length for [dimension][feature] is reached, it's no needs to add more tuples.
				if (this.currentTupleLength[dimension][feature] == MaxTupleLength)
				{
					return;
				}

				this.currentTupleLength[dimension][feature]++;

				int tupleLength = this.currentTupleLength[dimension][feature];

				if (tupleLength == 1)
				{
					Tuple tuple = new Tuple();

					tuple.Add(new FeatureInfo(dimension, feature));

					if (this.testCases.IsTupleCovered(tuple))
					{
						return;
					}

					this.uncoveredTuples[dimension][feature].Add(tuple);
				}
				else
				{
					for (int d = 0; d < this.dimensions.Length; d++)
					{
						for (int f = 0; f < this.dimensions[d]; f++)
						{
							Tuple tuple = new Tuple();
							tuple.Add(new FeatureInfo(d, f));

							if (tuple[0].Dimension == dimension)
							{
								continue;
							}

							tuple.Add(new FeatureInfo(dimension, feature));

							if (this.testCases.IsTupleCovered(tuple))
							{
								continue;
							}

							this.uncoveredTuples[dimension][feature].Add(tuple);
						}
					}
				}
			}
Example #5
0
        Tuple<int, int, int> RunSolverFunction(SolverDelegate solverFunction)
        {
            Tuple<int,int,int> totals = new Tuple<int, int, int>(0,0,0);
            for(int counter=1;counter<=StaticSudoku.Dimension;counter++)
            {
                int solved = 0;
                int eliminated = solverFunction(counter);

                if(eliminated > 0)
                {
                    totals = totals.Add(eliminated, solved);
                    totals = totals.Add(ScanNakedSingles());
                }
            }
            return totals;
        }
Example #6
0
        Tuple<int, int, int> ExecutePlan(List<SolverDelegate> functionList)
        {
            Tuple<int,int,int> total = new Tuple<int, int, int>(0,0,0);
            Tuple<int, int, int> round;

            do
            {
                round = new Tuple<int, int, int>(0,0,0);

                foreach (SolverDelegate function in functionList)
                {
                    for (int counter = 1; counter <= StaticSudoku.Dimension; counter++)
                    {
                        round = round.Add(EliminateCandidates(), 0);
                        round = round.Add(function(counter), 0);
                        //round = round.Add(RunSolverFunction(function));
                        round = round.Add(ScanNakedSingles());
                    }
                }

                total = total.Add(round);

            }
            while (round.Item1 + round.Item2 > 0);

            return total;
        }
    public void Go()
    {
      var list = getFuturesOutputList();

      var startDate = DateTime.Now.AddMonths(-2);

      foreach (var item in list.Where(x => x.LastTrade > startDate))
      {
        using (var dc = SymmetryDataSource.ReadWrite())
        {
          try
          {
            item.InflateDetails();
            // we get some dodgy items eg TYZ6 with lasttrade date of Sept 2015
            if (!item.LastTradeMakesSense())
            {
              Logger.Error(
                string.Format("Not going to process dodgy looking item from bbg. Ticker = {0} and LastTrade={1}",
                  item.BbgCode, item.LastTrade), typeof (FutureMaintainer));
              continue;
            }

            Logger.Info(string.Format("Considering {0}...", item.BbgCode), typeof (FutureMaintainer));

            // try to find the item using last trade date first as this was retrieved by getting the future chain.
            // we might be able to prevent hitting bloomberg against for the contract static specifically
            var fi = findPossible(item, item.LastTrade, dc);

            if (fi == null && item.InflateDetails())
              fi = findPossible(item, item.Maturity, dc);

            // if we've managed to find the contract and it hasn't got the bloombergID that we're looking for, then update it
            if (fi != null && String.Compare(item.BbgCode, fi.SymmetryCode, StringComparison.OrdinalIgnoreCase) != 0)
            {
              Logger.Info(string.Format("Changing SymmetryCode from {0} to {1}", fi.SymmetryCode, item.BbgCode),
                typeof (FutureMaintainer));
              fi.SymmetryCode = item.BbgCode;
              Symmetry.Data.FIChangeTracking.SetModified(fi, dc);
              dc.SaveChanges();
            }


            if (fi == null)
            {
              if (item.InflateDetails())
              {
                Logger.Info(string.Format("Adding {0} to FI table...", item.BbgCode), typeof (FutureMaintainer));

                fi = dc.FIs.Add(new FI()
                {
                  Currency = item.Ccy,
                  SymmetryCode = item.BbgCode,
                  InstrumentType = item.InstType,
                  DisplayName = item.Description,
                  Maturity = item.Maturity,
                  Tenor = item.Tenor
                });

                dc.SaveChanges();
              }
              else
              {
                continue;
              }
            }


            var maps = new Tuple<IdentifierType, string>[]
            {
              new Tuple<IdentifierType, string>(IdentifierType.Bloomberg, item.BbgCode),
              new Tuple<IdentifierType, string>(IdentifierType.RIC, item.RIC),
              new Tuple<IdentifierType, string>(IdentifierType.Orchestrade, item.OT_ID)
            }.ToList();


            if (fi.InstrumentType == InstrumentType.IRFuture && item.LastTrade > DateTime.Today)
              maps.Add(new Tuple<IdentifierType, string>(IdentifierType.MLPCurveCode, item.RIC));

            foreach (var map in maps)
            {
              if (string.IsNullOrEmpty(map.Item2))
                continue;

              var identifiers = FIHelpers.GetFIIdentifiers(fi.SymmetryCode, map.Item1, dc,
                Symmetry.Core.ThrowBehavior.DontThrow);

              //if (identifiers != null && identifiers.Length > 1)
              //  System.Diagnostics.Debugger.Break();

              if (identifiers == null || identifiers.Length < 2)
              {
                // no point updating if already the same
                if (identifiers != null && identifiers.Length == 1 &&
                    String.Compare(identifiers[0], map.Item2, StringComparison.OrdinalIgnoreCase) == 0)
                  continue;

                Logger.Info(
                  string.Format("Setting {0} identifier : [{1}] = [{2}]", fi.SymmetryCode, map.Item1, map.Item2),
                  typeof (FutureMaintainer));

                FIBondHelpers.SetOrUpdateIdentifier(fi, map.Item1, map.Item2, dc);
              }
            }

            if (fi.FIFuture == null)
            {
              Logger.Info(string.Format("Adding FIFuture entry for {0}", item.BbgCode), typeof (FutureMaintainer));

              item.InflateDetails();
              fi.FIFuture = new FIFuture()
              {
                BbgBase = item.SourceSpec.BbgStart,
                BbgSuffix = item.SourceSpec.BbgSuffix,
                ReutersBase = item.SourceSpec.RICStart,
                Ccy = item.Ccy,
                Exchange = item.Exchange,
                FirstNotice = item.FirstNotice,
                FirstTradeDate = item.FirstTrade,
                LastDelivery = item.LastDelivery,
                LastTradeDate = item.LastTrade
              };
              dc.SaveChanges();
            }

            dc.SaveChanges();
          }
          catch (Exception ex_)
          {
            Logger.Error(string.Format("Error thrown updating {0}", item.BbgCode), typeof (FutureMaintainer));
          }
        }
      }
      MaintainIntradayFuturesStatics();
    }