internal static bool TestEqualWithWord(IAutomat a1, IAutomat a2, string w) { bool ac1 = a1.AcceptWord(w); bool ac2 = a2.AcceptWord(w); if (ac1 != ac2) { Utils.DebugMessage($"word '{w}' is {ac1}:{a1.Name} != {ac2}:{a2.Name}", a1, Uni.Utils.eDebugLogLevel.Normal); return(false); } else { return(true); } }
public ApartmentRentedState(IAutomat automat) { _automat = automat; }
public WaitingState( IAutomat automat ) { this.automat = automat; DefaultMessage = "You have to submit an application"; }
public ApartmentRentedState(IAutomat automat) { DefaultMessage = "Hang on, we're renting you an apartment."; this.automat = automat; }
public GotApplicationState(IAutomat automat) { _automat = automat; _random = new Random(DateTime.Now.Millisecond); }
public TuringCycleException(string msg, IAutomat automat) : base(msg, automat) { Uni.Utils.DebugMessage(msg, Uni.Utils.eDebugLogLevel.Verbose); }
public GotApplicationState( IAutomat automat ) { DefaultMessage = "We already got your application"; this.automat = automat; }
/// <returns>bool empiric _guess_ if its pumpbar</returns> public static PumpResult TestPumpbar(IAutomat Automat, int pumpLaenge, int words = 200, int maxWordLen = 50, int exponentMax = 20, int exponentCount = 10) { int allAcceptedWordsPass = 0; if (Automat.AcceptedStates.Length == 0) { return(PumpResult.NoAcceptedWordExists); } bool foundAtLeastOneAcceptedWordForTest = false; foreach (string w in Automat.GetRandomWords(words, pumpLaenge, maxWordLen, System.Array.Empty <string>())) { if (Automat.AcceptWord(w)) { foundAtLeastOneAcceptedWordForTest = true; allAcceptedWordsPass = 0; foreach (string[] strParts in StringParts3(w)) { string x = strParts[0]; string y = strParts[1]; string z = strParts[2]; Utils.DebugMessage($"word {w}=({x}.{y}.{z})", Automat, Uni.Utils.eDebugLogLevel.Verbose); if (!((x + y).Length <= pumpLaenge)) { Utils.DebugMessage($"word |x+y={x.Length}+{y.Length}|<={pumpLaenge}", Automat, Uni.Utils.eDebugLogLevel.Verbose); continue; // throw new PumpingException($"|xy|={(x + y).Length}>{pumpLaenge}"); } if (y.Length == 0) { Utils.DebugMessage($"word |y={y}|=0", Automat, Uni.Utils.eDebugLogLevel.Verbose); continue; // throw new PumpingException($"|y|=0, y={Utils.EPSILON}"); } for (int i = 0; i < exponentCount; i++) { int k = Uni.Utils.RND.Next(1, exponentMax); string wk = x + string.Concat(System.Linq.Enumerable.Repeat(y, k)) + z; if (Automat.AcceptWord(wk)) { Utils.DebugMessage($"{w} {pumpLaenge}-pumpbar for {x}.{y}.{z}", Automat, Uni.Utils.eDebugLogLevel.Verbose); allAcceptedWordsPass++; } } if (allAcceptedWordsPass >= exponentCount) { break; } } //next strParts if (allAcceptedWordsPass < exponentCount) { return(PumpResult.NotPumpable); } } //endif AcceptWord } //next w if (!foundAtLeastOneAcceptedWordForTest) { return(PumpResult.NoAcceptedWordFound); } if (allAcceptedWordsPass > 0) { Utils.DebugMessage($"{pumpLaenge}-pumpbar for |{allAcceptedWordsPass}| words", Automat, Uni.Utils.eDebugLogLevel.Verbose); return(PumpResult.Pumpable); } else { Utils.DebugMessage($"not {pumpLaenge}-pumpbar", Automat, Uni.Utils.eDebugLogLevel.Verbose); } return(PumpResult.NotPumpable); }
public WaitingState(IAutomat automat) { _automat = automat; }
public static Bitmap DrawAutomat(IAutomat A, uint?highlightState = null) { var alreadyDrawn = new IncDictionary <int>(); int lastCurveHeigth = 3 * CURVE_BONUS; float relFactor = 1; var vls = A.VisualizationLines(); if (vls.Length > A.StatesCount * 3) { relFactor *= vls.Length / (A.StatesCount * 3); Utils.DebugMessage($"corrected bmpRelFactor to {relFactor} by transform count", A, Uni.Utils.eDebugLogLevel.Verbose); } else if (A.Alphabet.Length > A.StatesCount * 4) { relFactor *= A.Alphabet.Length / (A.StatesCount * 4); Utils.DebugMessage($"corrected bmpRelFactor to {relFactor} by alphabet count", A, Uni.Utils.eDebugLogLevel.Verbose); } int bmpwidth = Math.Max(500, (int)(IMAGE_SPACE + (A.StatesCount) * (STATE_DIAMETER + IMAGE_SPACE) * relFactor)); var bmp = new Bitmap(bmpwidth, (int)(bmpwidth / 1.5)); Graphics g = Graphics.FromImage(bmp); Font headFont = new Font(SystemFonts.DefaultFont.FontFamily, Math.Max(14, bmpwidth / 60)); int vCenter = (int)(bmp.Height / 2.6); g.FillRectangle(Brushes.White, 0, 0, bmp.Width, bmp.Height); g.DrawString(A.Name, headFont, Brushes.Black, 20, 20); //Draw full declaration to bottom string FullDesc = A.ToString(); try { FullDesc = FullDesc.Replace(A.Name, "").Trim(); } catch { } const int MARGIN = 10; var FullDescSize = g.MeasureString(FullDesc, CourierNewFont); if (FullDescSize.Width < bmpwidth - MARGIN * 2) { g.DrawString(FullDesc, CourierNewFont, Brushes.Black, 15f, bmp.Height - FullDescSize.Height * 1.5f); } else { int DescPartCount = (int)Math.Ceiling(FullDescSize.Width / (bmpwidth - MARGIN * 2)); int toStringSplitFactor = (int)Math.Ceiling((float)FullDesc.Length / DescPartCount); for (int i = 0; i < DescPartCount; i++) { string rowString = FullDesc.Substring(i * toStringSplitFactor, Math.Min(toStringSplitFactor, FullDesc.Length - i * toStringSplitFactor)); g.DrawString(rowString, CourierNewFont, Brushes.Black, 15, bmp.Height - (DescPartCount - i + 1) * (FullDescSize.Height)); } } // draw States for (uint iq = 0; iq < A.StatesCount; iq++) { var strSize = g.MeasureString(A.States[iq], CourierNewFont); g.DrawString(A.States[iq], CourierNewFont, Brushes.Black, qPos(iq) + STATE_DIAMETER / 2 - strSize.Width / 2, vCenter - strSize.Height / 2); var ellipsePen = PEN; if (A.IsAcceptedState(iq)) { ellipsePen = PEN_DOUBLE; } if (iq == highlightState) { ellipsePen = Pens.Red; } g.DrawEllipse(ellipsePen, qPos(iq), vCenter - STATE_DIAMETER / 2, STATE_DIAMETER, STATE_DIAMETER); } // draw Start Arrow { int lineX = qPos(A.StartState) - IMAGE_SPACE / 2; int lineX2 = qPos(A.StartState); g.DrawLine(PEN_START_ARROW, lineX, vCenter, lineX2, vCenter); } // draw Transform Lines, depends which automat, because of inconsistent transform inheritance and nondeterministic transform foreach (var vtl in vls) { DrawTransformLine(ref g, vtl.Item1, vtl.Item2, vtl.Item3, vCenter, ref lastCurveHeigth, ref alreadyDrawn); } return(bmp); }
public FullyRentedState(IAutomat automat) { DefaultMessage = "Sorry We're Fully Rented."; this.automat = automat; }
public static void SaveAutomatImageToTemp(this IAutomat automat) => Visualization.DrawAutomat(automat).Save(System.Environment.ExpandEnvironmentVariables($@"%temp%\automat\{automat.Name}.png"));
public FullyRentedState( IAutomat automat ) { DefaultMessage = "Sorry We're Fully Rented."; this.automat = automat; }
public FullyRentedState(IAutomat automat) { _automat = automat; }
public GotApplicationState(IAutomat automat) { DefaultMessage = "We already got your application"; this.automat = automat; }
public WaitingState(IAutomat automat) { this.automat = automat; DefaultMessage = "You have to submit an application"; }
public ApartmentRentedState( IAutomat automat ) { DefaultMessage = "Hang on, we're renting you an apartment."; this.automat = automat; }