public BeliefState GetInitialBelief() { Debug.WriteLine("Generating initial belief state"); BeliefState bs = new BeliefState(this); foreach (GroundedPredicate p in m_lKnown) { if (p.Name == "=") { bs.FunctionValues[p.Constants[0].Name] = double.Parse(p.Constants[1].Name); } else { bs.AddObserved(p); } } foreach (CompoundFormula cf in m_lHidden) { Formula fReduced = cf.Reduce(m_lKnown); if (fReduced is CompoundFormula) { bs.AddInitialStateFormula(((CompoundFormula)fReduced)); } } //bs.InitDNF(); return(bs); }
public List <PartiallySpecifiedState> GetInitialStates() { List <PartiallySpecifiedState> lpssInitialPossibleStates = new List <PartiallySpecifiedState>(); BeliefState bsInitial = GetInitialBelief();//, bsCurrent = bsInitial, bsNext = null; PartiallySpecifiedState pssInitial = bsInitial.GetPartiallySpecifiedState(); lpssInitialPossibleStates.Add(pssInitial); foreach (var hiddenItems in Hidden) { if (hiddenItems is CompoundFormula) { List <PartiallySpecifiedState> stateAdditions = new List <PartiallySpecifiedState>(); foreach (var item in hiddenItems.Operands) { foreach (var pssCurrentCheckedState in lpssInitialPossibleStates) { PartiallySpecifiedState pssNew = pssCurrentCheckedState.Clone(); pssNew.AddObserved(item); stateAdditions.Add(pssNew); } } lpssInitialPossibleStates = stateAdditions; } else { throw new NotImplementedException(); } } return(lpssInitialPossibleStates); }
//public string agentMove(Kernel.Point pLoc, Kernel.Point cLoc) //{ // switch (cLoc.Column - pLoc.Column) // { // case 1: // return "Agent Moves Right"; // case -1: // return "Agent Moves Loft"; // } // switch (cLoc.Row - pLoc.Row) // { // case 1: // return "Agent Moves Up"; // case -1: // return "Agent Moves Down"; // } // return "Agent Didnt Move"; //} public override void UpdateState(BeliefState bs) { Belief = bs; int iSize = GetGridSize(); //your code here Kernel.Matrix bMatrix = new Kernel.Matrix(new Kernel.Point((byte)iSize, (byte)iSize)); delay(); int iX = 0, iY = 0; GetAgentLocation(out iX, out iY); for (int i = 1; i <= iSize; i++) { for (int j = 1; j <= iSize; j++) { if (IsLocationBlocked(i, j)) { Console.WriteLine("Blocked " + i + "," + j); // if (board.Created) board.addConsoleText("Blocked " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.LCellType.Fix); } else if (IsPossibleLocation(i, j)) { Console.WriteLine("Agent might be at " + i + "," + j); // if (board.Created) board.addConsoleText("Agent might be at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.LCellType.PAgent); } else { bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.LCellType.None); } } } Console.WriteLine("Agent at " + iX + "," + iY); // if (board.Created) board.addConsoleText(idx + ") Observation: " + obs + "\r\n Action: " + act + "\r\n Agent at: " + iX + "," + iY + "\r\n ----------------------------------------"); obs = ""; act = ""; //if (board.Created) board.addConsoleText(idx + ") " + "Observed:" + GetObservation(bs) + "\r\n Action:" + agentMove(cLoc, new Kernel.Point((byte)iY, (byte)iX)) + "\r\n(Agent at " + iX + "," + iY + ")\r\n ----------------------------------------"); //if (locFlg) { if (board.Created) board.addConsoleText(idx+ ") " + agentMove(cLoc, new Kernel.Point((byte)iY, (byte)iX)) + " (Agent at " + iX + "," + iY+ ")\r\n ----------------------------------------"); } //else //{ // locFlg = true; // if (board.Created) board.addConsoleText(idx + ") Agent at " + iX + "," + iY + "\r\n ----------------------------------------"); //} idx++; cLoc = new Kernel.Point((byte)iY, (byte)iX); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - iY), (byte)(iX - 1)), Kernel.LCellType.Agent); //if (board.Created) // { board.setMatrix(bMatrix); if (board.fF == true) { board.fF = false; board.stopSpeed(); } // } }
public void WriteKnowledgeProblem(string sFileName, BeliefState bs) { StreamWriter sw = new StreamWriter(sFileName); sw.WriteLine("(define (problem K" + Problem.Name + ")"); sw.WriteLine("(:domain K" + Problem.Domain.Name + ")"); sw.WriteLine("(:init"); //ff doesn't like the and (and"); /* * foreach (GroundedPredicate gpKnow in Problem.Known) * { * sw.Write("(K" + gpKnow.Name); * foreach (Constant c in gpKnow.Constants) * sw.Write(" " + c.Name); * sw.WriteLine(")"); * } * */ foreach (GroundedPredicate gp in bs.Observed) { sw.Write("(K" + gp.Name); foreach (Constant c in gp.Constants) { sw.Write(" " + c.Name); } sw.WriteLine(")"); } foreach (GroundedPredicate gp in Predicates) { sw.Write("(" + gp.Name); foreach (Constant c in gp.Constants) { sw.Write(" " + c.Name); } sw.WriteLine(")"); } sw.WriteLine(")"); HashSet <Predicate> lGoalPredicates = new HashSet <Predicate>(); Problem.Goal.GetAllPredicates(lGoalPredicates); string sGoal = Problem.Goal.ToString(); sw.WriteLine("(:goal " + sGoal + ")"); /* Not sure whether we have to KNOW that we have the goal * sw.Write("(:goal (and " + sGoal); * foreach (Predicate p in lGoalPredicates) * Problem.Domain.WriteKnowledgePredicate(sw, p); * sw.WriteLine("))"); */ sw.WriteLine(")"); sw.Close(); }
internal void WriteTaggedProblem(string p, BeliefState bsCurrent) { throw new NotImplementedException(); }
//public string agentMove(Kernel.Point pLoc, Kernel.Point cLoc) //{ // switch (cLoc.Column - pLoc.Column) // { // case 1: // return "Agent Moves Right"; // case -1: // return "Agent Moves Loft"; // } // switch (cLoc.Row - pLoc.Row) // { // case 1: // return "Agent Moves Up"; // case -1: // return "Agent Moves Down"; // } // return "Agent Didnt Move"; //} public override void UpdateState(BeliefState bs) { Belief = bs; int iSize = GetGridSize(); //your code here Kernel.Matrix bMatrix = new Kernel.Matrix(new Kernel.Point((byte)iSize, (byte)iSize)); delay(); int iX = 0, iY = 0; GetAgentLocation(out iX, out iY); cLoc = new Kernel.Point((byte)iY, (byte)iX); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - iY), (byte)(iX - 1)), Kernel.MCellType.Agent); for (int i = 1; i <= iSize; i++) { for (int j = 1; j <= iSize; j++) { //if (IsUnNone(i, j)) //{ // Console.WriteLine("UnNone " + i + "," + j); // // if (board.Created) board.addConsoleText("Blocked " + i + "," + j); // bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.UnNone); // bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j+1), (byte)(i - 1)), Kernel.MCellType.Pfeeling); // //bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i)), Kernel.MCellType.Pfeeling); // bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j - 1), (byte)(i - 1)), Kernel.MCellType.Pfeeling); // bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 2)), Kernel.MCellType.Pfeeling); //} if (IsPossibaleFeeling(i, j) && !((i == iX) && (j == iY))) { //Console.WriteLine("Breeze and Stench at " + i + "," + j); // if (board.Created) board.addConsoleText("Agent might be at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.Pfeeling); } if (IsUnSafe(i, j)) { //Console.WriteLine("Breeze and Stench at " + i + "," + j); // if (board.Created) board.addConsoleText("Agent might be at " + i + "," + j); if (j > i) { bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.UnNoneUp); } if (j < i) { bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.UnNoneDown); } } else if (IsSafe(i, j)) { if (i == iX && j == iY) { //Console.WriteLine("Breeze and Stench at " + i + "," + j); // if (board.Created) board.addConsoleText("Agent might be at " + i + "," + j); if (j > i) { bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.ANoneUp); } if (j < i) { bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.ANoneDown); } } else { //Console.WriteLine("Breeze and Stench at " + i + "," + j); // if (board.Created) board.addConsoleText("Agent might be at " + i + "," + j); if (j > i) { bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.NoneUp); } if (j < i) { bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.NoneDown); } } } else if ((IsFeelingBreeze(i, j)) && (IsFeelingStench(i, j))) { if (i == iX && j == iY) { //Console.WriteLine("Breeze and Stench at " + i + "," + j); //if (board.Created) board.addConsoleText("Feeling Breeze & Stench at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.AbreezeStench); } else { Console.WriteLine("Breeze and Stench at " + i + "," + j); //if (board.Created) board.addConsoleText("Feeling Breeze & Stench at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.Feeling); } } else if (IsFeelingStench(i, j)) { if (i == iX && j == iY) { //Console.WriteLine("Breeze and Stench at " + i + "," + j); //if (board.Created) board.addConsoleText("Feeling Stench at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.Astench); } else { Console.WriteLine("Stench at " + i + "," + j); //if (board.Created) board.addConsoleText("Feeling Stench at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.Stench); } } else if (IsFeelingBreeze(i, j)) { if (i == iX && j == iY) { //Console.WriteLine("Breeze and Stench at " + i + "," + j); //if (board.Created) board.addConsoleText("Feeling Breeze at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.Abreeze); } else { Console.WriteLine("Breeze at " + i + "," + j); //if (board.Created) board.addConsoleText("Feeling Breeze at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.Breeze); } } if (IsWumpus(i, j) && (IsPit(i, j))) { Console.WriteLine("wumpus & pit at " + i + "," + j); //if (board.Created) board.addConsoleText("Wumpus & Pit at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.WumpusPit); } else if (IsWumpus(i, j)) { Console.WriteLine("wumpus at " + i + "," + j); //if (board.Created) board.addConsoleText("wumpus at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.Wumpus); } else if (IsPit(i, j)) { Console.WriteLine("pit at " + i + "," + j); //if (board.Created) board.addConsoleText("Pit at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.Pit); } if (IsCrown(i, j)) { if (i == iX && j == iY) { //Console.WriteLine("Breeze and Stench at " + i + "," + j); // if (board.Created) board.addConsoleText("Agent might be at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.Acrown); } else { Console.WriteLine("gold at " + i + "," + j); //if (board.Created) board.addConsoleText("Gold at at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.Crown); } } //else bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.LCellType.None); } } Console.WriteLine("Agent at " + iX + "," + iY); //if (board.Created) board.addConsoleText(idx + ") Observation: " + obs + "\r\n Action: " + act + "\r\n Agent at: " + iX + "," + iY + "\r\n ----------------------------------------"); obs = ""; act = ""; //if (board.Created) board.addConsoleText(idx + ") " +(GetObservation()!=""?"Observed:\r\n"+GetObservation():"No Observation\r\n") +"Action:\r\n"+ agentMove(cLoc, new Kernel.Point((byte)iY, (byte)iX)) + " (Agent at " + iX + "," + iY + ")\r\n ----------------------------------------"); //if (locFlg) { if (board.Created) board.addConsoleText(idx+ ") " + agentMove(cLoc, new Kernel.Point((byte)iY, (byte)iX)) + " (Agent at " + iX + "," + iY+ ")\r\n ----------------------------------------"); } //else //{ // locFlg = true; // if (board.Created) board.addConsoleText(idx + ") Agent at " + iX + "," + iY + "\r\n ----------------------------------------"); //} idx++; //if (board.Created) //{ board.setMatrix(bMatrix); if (board.fF == true) { board.fF = false; board.stopSpeed(); } // } }
public State WriteKReplannerProblem(string sFileName, BeliefState bsInitial) { StreamWriter sw = new StreamWriter(sFileName); sw.WriteLine("(define (problem " + Name + ")"); sw.WriteLine("(:domain " + Domain.Name + ")"); sw.WriteLine("(:init"); //ff doesn't like the and (and"); string sP = ""; foreach (GroundedPredicate gp in m_lKnown) { if (!gp.Negation) { sP = "(" + gp.Name; foreach (Constant c in gp.Constants) { sP += " " + c.Name; } sw.WriteLine("\t" + sP + ")"); } } //write invariants foreach (CompoundFormula cf in m_lHidden) { sw.WriteLine("\t" + cf.ToInvariant()); } sw.WriteLine(")"); //write hidden state sw.WriteLine("(:hidden"); State s = bsInitial.ChooseState(false); foreach (GroundedPredicate gp in s.Predicates) { if (!m_lKnown.Contains(gp)) { sP = ""; if (gp.Negation) { sP = "(not "; } sP += "(" + gp.Name; foreach (Constant c in gp.Constants) { sP += " " + c.Name; } if (gp.Negation) { sP += ")"; } sw.WriteLine("\t" + sP + ")"); } } sw.WriteLine(")"); sw.WriteLine("(:goal " + Goal + ")"); //sw.WriteLine("))"); sw.WriteLine(")"); sw.Close(); return(s); }
public abstract void UpdateState(BeliefState bs);