public BddPairList BuildStates() { BddPairList result = new BddPairList(); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { result.Add(X[i, j].Var, Xp[i, j].Var); result.Add(K[i, j].Var, Kp[i, j].Var); } } return(result); }
public string Run(bool reachableStates, bool traceLength, bool findtrace) { Kernel.Setup(); for (int i = 0; i < N; i++) { l[i] = new Bdd(i * 6); lp[i] = new Bdd(i * 6 + 1); m[i] = new Bdd(i * 6 + 2); mp[i] = new Bdd(i * 6 + 3); r[i] = new Bdd(i * 6 + 4); rp[i] = new Bdd(i * 6 + 5); } for (int i = 0; i < N * 3; i++) { pairList.Add(i * 2, i * 2 + 1); } I = InitialState(); E = EndState(); T = Transistions(); string answer = string.Empty; if (reachableStates) { Bdd R = Transition.ReachableStates(I, T, pairList); Bdd result = E >= R; answer += "ReachableStates: " + Kernel.SatCountVarSet(R) + Environment.NewLine; answer += "E >= R: " + result.U + Environment.NewLine; } int length = Transition.Tracelength(I, E, T, pairList); if (traceLength) { answer += "Tracelength: " + length + Environment.NewLine; } if (findtrace) { string trace; if (traceLength) { trace = Transition.FindTrace(I, E, T, transList, pairList, length); } else { trace = Transition.FindTrace(I, E, T, transList, pairList, Transition.Tracelength(I, E, T, pairList)); } answer += "Trace: " + trace; } return(answer); }
public string Run(bool reachableStates, bool traceLength, bool findtrace) { Kernel.Setup(); Bdd[] c = new Bdd[N]; Bdd[] cp = new Bdd[N]; Bdd[] h = new Bdd[N]; Bdd[] hp = new Bdd[N]; Bdd[] t = new Bdd[N]; Bdd[] tp = new Bdd[N]; Bdd I, T, R; BddPairList pairList = new BddPairList(); for (int n = 0; n < N * 3; n++) { pairList.Add(n * 2, n * 2 + 1); } for (int n = 0; n < N; n++) { c[n] = new Bdd(n * 6); cp[n] = new Bdd(n * 6 + 1); t[n] = new Bdd(n * 6 + 2); tp[n] = new Bdd(n * 6 + 3); h[n] = new Bdd(n * 6 + 4); hp[n] = new Bdd(n * 6 + 5); } I = InitialState(t, h, c); T = Transitions(t, tp, h, hp, c, cp); string answer = string.Empty; if (reachableStates) { R = Transition.ReachableStates(I, T, pairList); answer += "ReachableStates: " + Kernel.SatCountVarSet(R) + Environment.NewLine; } return(answer); }
public string Run(bool fake1, bool fake2, bool fake3) { Kernel.Setup(); Bdd I, E, T, R; Bdd[] ml = new Bdd[N]; // missionaries on left side Bdd[] mr = new Bdd[N]; // missionaries on right side Bdd[] mlp = new Bdd[N]; // missionaries on left' Bdd[] mrp = new Bdd[N]; Bdd[] cl = new Bdd[N]; // cannibles on left side Bdd[] cr = new Bdd[N]; // cannibles on right side Bdd[] clp = new Bdd[N]; Bdd[] crp = new Bdd[N]; Bdd br, brp, bl, blp; // the boat on right, the boat on right', the boat one the left, etc. BddPairList pairList = new BddPairList(); // *2 because we have both missionaries and cannibals // *2 because they all have two variables for (int i = 0; i < N * 2 * 2; i++) { pairList.Add(i * 2, i * 2 + 1); } for (int i = 0; i < N; i++) { ml[i] = new Bdd(i * 8); mlp[i] = new Bdd(i * 8 + 1); mr[i] = new Bdd(i * 8 + 2); mrp[i] = new Bdd(i * 8 + 3); cl[i] = new Bdd(i * 8 + 4); clp[i] = new Bdd(i * 8 + 5); cr[i] = new Bdd(i * 8 + 6); crp[i] = new Bdd(i * 8 + 7); } bl = new Bdd(N * 8); blp = new Bdd(N * 8 + 1); pairList.Add(N * 8, N * 8 + 1); br = new Bdd(N * 8 + 2); brp = new Bdd(N * 8 + 3); pairList.Add(N * 8 + 2, N * 8 + 3); I = InitialState(mr, cr, ml, cl, bl, br); E = EndState(mr, cr, ml, cl, bl, br); T = Transitions(mr, cr, ml, cl, mrp, crp, mlp, clp, bl, blp, br, brp); R = Transition.ReachableStates(I, T, pairList); Bdd result = E >= R; int tracelength = Transition.Tracelength(I, E, T, pairList); string trace = Transition.FindTrace(I, E, T, transList, pairList, tracelength); return("R=>E-satcount: " + Kernel.SatCountVarSet(result).ToString() + Environment.NewLine + "R-satcount: " + Kernel.SatCountVarSet(R).ToString() + Environment.NewLine + "Solution: " + trace + Environment.NewLine + "Tracelength: " + tracelength); }
// we are NOT using these rules /* * Regler: * * One location at a time: * ----------------------- * if m1r then !m1b & !m1l * if m2r then !m2b & !m2l * if m3r then !m3b & !m3l * * Shore rule * ---------- * if (m1r & m2r & !m3r) then * ((c1r & c2r & !c3r) | (!c1r & c2r & c3r) | (c1r & !c2r & c3r) | * (!c1r &!c2r & c3r) | (c1r & !c2r & !c3r) | (!c1r & c2r & !c3r) | * (!c1r & !c2r & !c3r)) * if (m1r & m2r & m3r) then ((c1r & c2r & c3r) & (above rule)) * * Boat rule (left) * --------- * if (m1bl & !m2bl & !m3bl) then * ((c1bl & !c2bl & !c3bl) | (!c1bl & !c2bl & c3bl) |!c1bl & c2bl & !c3bl) | * (!c1bl & !c2bl)) * if (!m1bl & !m2bl & m3b1) then * (c1bl & c2bl & !c3bl) | (!c1bl & c2bl & c3bl) | (c1bl & !c2bl & c3bl) | (above rule) * if (m1bl & m2bl & !m3b1) then * (!c1bl & !c2bl & !c3bl) * * */ public string Run() { Kernel.Setup(); Bdd I, E, T, R; Bdd[] ml = new Bdd[N]; // missionaries on left side Bdd[] mr = new Bdd[N]; // missionaries on right side Bdd[] mbr = new Bdd[N]; // missionaries on boat on right side Bdd[] mbl = new Bdd[N]; // missionaries on boat on left side Bdd[] mlp = new Bdd[N]; Bdd[] mrp = new Bdd[N]; Bdd[] mbrp = new Bdd[N]; Bdd[] mblp = new Bdd[N]; Bdd[] cl = new Bdd[N]; // cannibles on left side Bdd[] cr = new Bdd[N]; // cannibles on right side Bdd[] cbr = new Bdd[N]; // cannibles on boat on right side Bdd[] cbl = new Bdd[N]; // cannibles on boat on left side Bdd[] clp = new Bdd[N]; Bdd[] crp = new Bdd[N]; Bdd[] cbrp = new Bdd[N]; Bdd[] cblp = new Bdd[N]; Bdd br, brp, bl, blp; // the boat on right, the boat on right', the boat one the left, etc. //List<int> PreState = new List<int>(); //List<int> PostState = new List<int>(); BddPairList pairList = new BddPairList(); // *2 because we have both missionaries and cannibals // *4 because they all have four variables for (int i = 0; i < N * 2 * 4; i++) { pairList.Add(i * 2, i * 2 + 1); } //for (int i = 0; i < N*2*4; i++) //{ // PreState.Add(i * 2); // PostState.Add(i * 2 + 1); //} for (int i = 0; i < N; i++) { ml[i] = new Bdd(i * 16); mlp[i] = new Bdd(i * 16 + 1); mbl[i] = new Bdd(i * 16 + 2); mblp[i] = new Bdd(i * 16 + 3); mr[i] = new Bdd(i * 16 + 4); mrp[i] = new Bdd(i * 16 + 5); mbr[i] = new Bdd(i * 16 + 6); mbrp[i] = new Bdd(i * 16 + 7); cl[i] = new Bdd(i * 16 + 8); clp[i] = new Bdd(i * 16 + 9); cbl[i] = new Bdd(i * 16 + 10); cblp[i] = new Bdd(i * 16 + 11); cr[i] = new Bdd(i * 16 + 12); crp[i] = new Bdd(i * 16 + 13); cbr[i] = new Bdd(i * 16 + 14); cbrp[i] = new Bdd(i * 16 + 15); } bl = new Bdd(N * 16); blp = new Bdd(N * 16 + 1); pairList.Add(N * 16, N * 16 + 1); br = new Bdd(N * 16 + 2); brp = new Bdd(N * 16 + 3); pairList.Add(N * 16 + 2, N * 16 + 3); I = InitialState(mr, cr, ml, cl, mbr, cbr, mbl, cbl, bl, br); E = EndState(mr, cr, ml, cl, mbr, cbr, mbl, cbl, bl, br); T = Transitions(mr, cr, ml, cl, mbr, cbr, mbl, cbl, mrp, crp, mlp, clp, mbrp, cbrp, mblp, cblp, bl, blp, br, brp); //R = ReachableStates(I, T, PreState, PostState); R = ReachableStates(I, T, pairList); Bdd result = E & R; //BddSerializer.Serialize(R, "output2"); return("R&E-satcount: " + Kernel.SatCount(result).ToString() + Environment.NewLine + "R&E-anysat: " + Kernel.AnySat(result) + Environment.NewLine + "R-satcount: " + Kernel.SatCount(R).ToString() + Environment.NewLine + "LevelCount: " + count.ToString()); }