This document provides examples and explanations of the General Problem Solver (GPS) approach to artificial intelligence. It describes how GPS uses means-ends analysis to solve problems by finding operators that eliminate the difference between the current and goal states. The document then provides sample Python code implementing GPS and traces its step-by-step problem solving process for examples including moving blocks, turning on lights in a room, fixing a car, and solving the Tower of Hanoi puzzle.
Introduction to Scratch made during Abu Dhabi International Book Fair 2015.
Dr. Hind Zantout, from Heriot WattUniversity Dubai Campus introduces "Scratch" by demonstrating games and animations, and walking the audience through a few simple exercises, covering important concepts and features. Scratch is designed for children between 8-16 and is provided for free by MIT Media Labs. As children create with Scratch, they learn to think creatively, work collaboratively, and reason systematically.
Architecting Single Activity Applications (With or Without Fragments)Gabor Varadi
Presentation by Gabor Varadi (@zhuinden)
What Activity and Fragment actually are in Android
What are the problems they solve, and what are their downsides
How to use a custom solution that simplifies navigation in Android applications
https://github.com/Zhuinden/navigation-example
Introduction to Scratch made during Abu Dhabi International Book Fair 2015.
Dr. Hind Zantout, from Heriot WattUniversity Dubai Campus introduces "Scratch" by demonstrating games and animations, and walking the audience through a few simple exercises, covering important concepts and features. Scratch is designed for children between 8-16 and is provided for free by MIT Media Labs. As children create with Scratch, they learn to think creatively, work collaboratively, and reason systematically.
Architecting Single Activity Applications (With or Without Fragments)Gabor Varadi
Presentation by Gabor Varadi (@zhuinden)
What Activity and Fragment actually are in Android
What are the problems they solve, and what are their downsides
How to use a custom solution that simplifies navigation in Android applications
https://github.com/Zhuinden/navigation-example
Helping Data Teams with Puppet / Puppet Camp London - Apr 13, 2015Sergii Khomenko
Puppet is widely known in DevOps community, but not so popular in data teams. Nevertheless, Puppet could easily empower your data teams. In the talk presented hands-on experience of using Puppet for different data topics starting from configuring Windows machine for Business Intelligence and finishing with advanced ranking infrastructures based on Puppet.
The talk will walk you through the process of setting up a standalone Puppet configuration, that used for provisioning Windows machine to be utilized for Business Intelligence purposes like Tableau and Talend Big Data configurations, ETL scheduling etc. Second part of the talk will cover a use-case of Puppet for enabling a lean ranking infrastructure.
Achievement Unlocked: Drive development, increase velocity, and write blissfu...All Things Open
Presented at: All Things Open 2019
Presented by: Gleb Bahmutov, Cypress.io
Find the original slides: https://cypress.slides.com/cypress-io/achievement-unlocked
Lightening Talk I gave at Inaka in November 2015, after having developed Swift for a while.
It contains some lessons, mostly learned from the functional paradigm, that can be useful for any developer.
Problem Decomposition: Goal Trees, Rule Based Systems, Rule Based Expert Systems. Planning:
STRIPS, Forward and Backward State Space Planning, Goal Stack Planning, Plan Space Planning,
A Unified Framework For Planning. Constraint Satisfaction : N-Queens, Constraint Propagation,
Scene Labeling, Higher order and Directional Consistencies, Backtracking and Look ahead
Strategies.
To understand about Operator.
To learn about how many types of Operator.
To learn about Arithmetic Operator in C.
To use of Bitwise Operator in C.
To use of Relational Operator in C.
To learn about Logical Operator in C.
To learn about Assignment Operator in C.
To learn about Ternary Operator in C.
To learn about Unary & Binary Operator.
9 11 2
5 14 4
4 6 4
1 15 5
7 9 3
9 16 4
1 2 5
8 8 4
3 12 4
3 11 5
5 19 5
4 19 4
1 11 5
7 15 1
7 8 3
7 6 1
8 19 4
1 8 5
9 9 3
6 2 2
2 11 3
2 10 3
6 16 1
0 1 3
3 3 3
3 10 1
6 6 4
4 3 5
2 3 4
7 1 5
6 8 5
0 13 1
2 5 3
0 12 5
7 18 3
2 0 3
7 3 1
[IFT 102]
Introduction to Java Technologies
Lab 2: Control Flow & Arrays
Score: 50 pts (10 pts * 5)
I. Prelab Exercises (10 pts)
A. Textbook Sections 5.1-5.3
1. Rewrite each condition below in valid Java syntax (give a boolean expression):
a. x > y > z
b. x and y are both less than 0
c. neither x nor y is less than 0
d. x is equal to y but not equal to z
2. Suppose gpa is a variable containing the grade point average of a student. Suppose the goal of a program is to let a student know if he/she made the Dean’s list (the gpa must be 3.5 or above). Write an if... else... statement that prints out the appropriate message (either “Congratulations—you made the Dean’s List” or “Sorry you didn’t make the Dean’sList”).
3. Complete the following program to determine the raise and new salary for an employee by adding if ... else statements to compute the raise. The input to the program includes the current annual salary for the employee and a number indicating the performance rating (1=excellent, 2=good, and 3=poor). An employee with a rating of 1 will receive a 6% raise, an employee with a rating of 2 will receive a 4% raise, and one with a rating of 3 will receive a 1.5% raise.
// ************************************************************
// Salary.java
// Computes the raise and new salary for an employee
// ************************************************************
import java.util.Scanner;
public class Salary
{
public static void main (String[] args)
{
double currentSalary; // current annual salary
double rating; // performance rating
double raise; // dollar amount of the raise
Scanner scan = new Scanner(System.in);
// Get the current salary and performance rating
System.out.print ("Enter the current salary: ");
currentSalary = scan.nextDouble();
System.out.print ("Enter the performance rating: ");
rating = scan.nextDouble();
// Compute the raise -- Use if ... else ...
// Print the results
System.out.println ("Amount of your raise: $" + raise);
System.out.println ("Your new salary: $" + currentSalary + raise);
}
}
B. Textbook Section 5.4
In a while loop, execution of a set of statements (the body of the loop) continues until the boolean expression controlling the loop (the condition) becomes false. As for an if statement, the condition must be enclosed in parentheses. For example, the loop below prints the numbers from 1 to LIMIT:
final int LIMIT = 100; // setup
int count = 1;
while (count <= LIMIT) // condition
{ // body
System.out.println(count); // -- perform task
count = count + 1; // -- update condition
}
There are three parts to a loop:
· The setup, or initialization. This comes before the actual loop, and is where variables are initialized in preparation for the first time through the loop..
In Ember.js, routes and templates dictate the architecture of your app. This presentation will talk about why this is, and what tools Ember provides to manage architectural complexity.
Building Real Time Systems on MongoDB Using the Oplog at StripeStripe
MongoDB's oplog is possibly its most underrated feature. The oplog is vital as the basis on which replication is built, but its value doesn't stop there. Unlike the MySQL binlog, which is poorly documented and not directly exposed to MySQL clients, the oplog is a well-documented, structured format for changes that is query-able through the same mechanisms as your data. This allows many types of powerful, application-driven streaming or transformation. At Stripe, we've used the MongoDB oplog to create PostgresSQL, HBase, and ElasticSearch mirrors of our data. We've built a simple real-time trigger mechanism for detecting new data. And we've even used it to recover data. In this talk, we'll show you how we use the MongoDB oplog, and how you can build powerful reactive streaming data applications on top of it.
If you'd like to see the presentation with presenter's notes, I've published my Google Docs presentation at https://docs.google.com/presentation/d/19NcoFI9BG7PwLoBV7zvidjs2VLgQWeVVcUd7Xc7NoV0/pub
Originally given at MongoDB World 2014 in New York
Helping Data Teams with Puppet / Puppet Camp London - Apr 13, 2015Sergii Khomenko
Puppet is widely known in DevOps community, but not so popular in data teams. Nevertheless, Puppet could easily empower your data teams. In the talk presented hands-on experience of using Puppet for different data topics starting from configuring Windows machine for Business Intelligence and finishing with advanced ranking infrastructures based on Puppet.
The talk will walk you through the process of setting up a standalone Puppet configuration, that used for provisioning Windows machine to be utilized for Business Intelligence purposes like Tableau and Talend Big Data configurations, ETL scheduling etc. Second part of the talk will cover a use-case of Puppet for enabling a lean ranking infrastructure.
Achievement Unlocked: Drive development, increase velocity, and write blissfu...All Things Open
Presented at: All Things Open 2019
Presented by: Gleb Bahmutov, Cypress.io
Find the original slides: https://cypress.slides.com/cypress-io/achievement-unlocked
Lightening Talk I gave at Inaka in November 2015, after having developed Swift for a while.
It contains some lessons, mostly learned from the functional paradigm, that can be useful for any developer.
Problem Decomposition: Goal Trees, Rule Based Systems, Rule Based Expert Systems. Planning:
STRIPS, Forward and Backward State Space Planning, Goal Stack Planning, Plan Space Planning,
A Unified Framework For Planning. Constraint Satisfaction : N-Queens, Constraint Propagation,
Scene Labeling, Higher order and Directional Consistencies, Backtracking and Look ahead
Strategies.
To understand about Operator.
To learn about how many types of Operator.
To learn about Arithmetic Operator in C.
To use of Bitwise Operator in C.
To use of Relational Operator in C.
To learn about Logical Operator in C.
To learn about Assignment Operator in C.
To learn about Ternary Operator in C.
To learn about Unary & Binary Operator.
9 11 2
5 14 4
4 6 4
1 15 5
7 9 3
9 16 4
1 2 5
8 8 4
3 12 4
3 11 5
5 19 5
4 19 4
1 11 5
7 15 1
7 8 3
7 6 1
8 19 4
1 8 5
9 9 3
6 2 2
2 11 3
2 10 3
6 16 1
0 1 3
3 3 3
3 10 1
6 6 4
4 3 5
2 3 4
7 1 5
6 8 5
0 13 1
2 5 3
0 12 5
7 18 3
2 0 3
7 3 1
[IFT 102]
Introduction to Java Technologies
Lab 2: Control Flow & Arrays
Score: 50 pts (10 pts * 5)
I. Prelab Exercises (10 pts)
A. Textbook Sections 5.1-5.3
1. Rewrite each condition below in valid Java syntax (give a boolean expression):
a. x > y > z
b. x and y are both less than 0
c. neither x nor y is less than 0
d. x is equal to y but not equal to z
2. Suppose gpa is a variable containing the grade point average of a student. Suppose the goal of a program is to let a student know if he/she made the Dean’s list (the gpa must be 3.5 or above). Write an if... else... statement that prints out the appropriate message (either “Congratulations—you made the Dean’s List” or “Sorry you didn’t make the Dean’sList”).
3. Complete the following program to determine the raise and new salary for an employee by adding if ... else statements to compute the raise. The input to the program includes the current annual salary for the employee and a number indicating the performance rating (1=excellent, 2=good, and 3=poor). An employee with a rating of 1 will receive a 6% raise, an employee with a rating of 2 will receive a 4% raise, and one with a rating of 3 will receive a 1.5% raise.
// ************************************************************
// Salary.java
// Computes the raise and new salary for an employee
// ************************************************************
import java.util.Scanner;
public class Salary
{
public static void main (String[] args)
{
double currentSalary; // current annual salary
double rating; // performance rating
double raise; // dollar amount of the raise
Scanner scan = new Scanner(System.in);
// Get the current salary and performance rating
System.out.print ("Enter the current salary: ");
currentSalary = scan.nextDouble();
System.out.print ("Enter the performance rating: ");
rating = scan.nextDouble();
// Compute the raise -- Use if ... else ...
// Print the results
System.out.println ("Amount of your raise: $" + raise);
System.out.println ("Your new salary: $" + currentSalary + raise);
}
}
B. Textbook Section 5.4
In a while loop, execution of a set of statements (the body of the loop) continues until the boolean expression controlling the loop (the condition) becomes false. As for an if statement, the condition must be enclosed in parentheses. For example, the loop below prints the numbers from 1 to LIMIT:
final int LIMIT = 100; // setup
int count = 1;
while (count <= LIMIT) // condition
{ // body
System.out.println(count); // -- perform task
count = count + 1; // -- update condition
}
There are three parts to a loop:
· The setup, or initialization. This comes before the actual loop, and is where variables are initialized in preparation for the first time through the loop..
In Ember.js, routes and templates dictate the architecture of your app. This presentation will talk about why this is, and what tools Ember provides to manage architectural complexity.
Building Real Time Systems on MongoDB Using the Oplog at StripeStripe
MongoDB's oplog is possibly its most underrated feature. The oplog is vital as the basis on which replication is built, but its value doesn't stop there. Unlike the MySQL binlog, which is poorly documented and not directly exposed to MySQL clients, the oplog is a well-documented, structured format for changes that is query-able through the same mechanisms as your data. This allows many types of powerful, application-driven streaming or transformation. At Stripe, we've used the MongoDB oplog to create PostgresSQL, HBase, and ElasticSearch mirrors of our data. We've built a simple real-time trigger mechanism for detecting new data. And we've even used it to recover data. In this talk, we'll show you how we use the MongoDB oplog, and how you can build powerful reactive streaming data applications on top of it.
If you'd like to see the presentation with presenter's notes, I've published my Google Docs presentation at https://docs.google.com/presentation/d/19NcoFI9BG7PwLoBV7zvidjs2VLgQWeVVcUd7Xc7NoV0/pub
Originally given at MongoDB World 2014 in New York
Explore our comprehensive data analysis project presentation on predicting product ad campaign performance. Learn how data-driven insights can optimize your marketing strategies and enhance campaign effectiveness. Perfect for professionals and students looking to understand the power of data analysis in advertising. for more details visit: https://bostoninstituteofanalytics.org/data-science-and-artificial-intelligence/
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...Subhajit Sahu
Abstract — Levelwise PageRank is an alternative method of PageRank computation which decomposes the input graph into a directed acyclic block-graph of strongly connected components, and processes them in topological order, one level at a time. This enables calculation for ranks in a distributed fashion without per-iteration communication, unlike the standard method where all vertices are processed in each iteration. It however comes with a precondition of the absence of dead ends in the input graph. Here, the native non-distributed performance of Levelwise PageRank was compared against Monolithic PageRank on a CPU as well as a GPU. To ensure a fair comparison, Monolithic PageRank was also performed on a graph where vertices were split by components. Results indicate that Levelwise PageRank is about as fast as Monolithic PageRank on the CPU, but quite a bit slower on the GPU. Slowdown on the GPU is likely caused by a large submission of small workloads, and expected to be non-issue when the computation is performed on massive graphs.
Adjusting primitives for graph : SHORT REPORT / NOTESSubhajit Sahu
Graph algorithms, like PageRank Compressed Sparse Row (CSR) is an adjacency-list based graph representation that is
Multiply with different modes (map)
1. Performance of sequential execution based vs OpenMP based vector multiply.
2. Comparing various launch configs for CUDA based vector multiply.
Sum with different storage types (reduce)
1. Performance of vector element sum using float vs bfloat16 as the storage type.
Sum with different modes (reduce)
1. Performance of sequential execution based vs OpenMP based vector element sum.
2. Performance of memcpy vs in-place based CUDA based vector element sum.
3. Comparing various launch configs for CUDA based vector element sum (memcpy).
4. Comparing various launch configs for CUDA based vector element sum (in-place).
Sum with in-place strategies of CUDA mode (reduce)
1. Comparing various launch configs for CUDA based vector element sum (in-place).
Adjusting primitives for graph : SHORT REPORT / NOTES
AI-WK-8-Lec-15-16.pdf
1. Dr. Sadaf Gull / sadaf@biit.edu.pk Lecture#15,16
Artificial Intelligence (CS-636)
Objectives:
✓ General Problem Solver (GPS)
✓ Examples:
✓ GPS Code in Python
NOTE: The credit of the python version of GPS goes to Dr. Umair (Associate professor)
who worked in BIIT for a very long time. We appreciate his efforts in this regard.
General Problem Solver
The main idea of GPS is to solve a problem using a process called means-ends analysis, where
the problem is stated in terms of what we want to achieve at the end. We can solve a problem if
we can find some way to eliminate “the difference between what I have (current state) and
what I want (goal state and search forward to the goal, or to employ a mixture of different
search strategies.
In Python we can refine these notions as follows:
1. We can represent the current state of the world —“what I have”— or the goal state –“what
I want” – as sets of conditions. We can use lists to implement these states.. Thus, a
typical goal might be the list of two conditions (rich famous) and a typical current state
might be (unknown poor).
2. We need a list of allowable operators. This list will be constant over the course of a
problem, or even a series of problems, but we want to be able to change it and tackle a
new problem domain. The list of operators will contain dictionaries whose keys will be
✓ action
✓ preconditions
✓ add
✓ delete
3. An operator can be represented as a structure composed of an action, a list of
preconditions and a list of effects. We can place limits on the kinds of possible effects
by saying that an effect either adds or deletes a condition from the current state. Thus,
the list of effects can be split into an add-list and a delete-list.
4. A complete problem is described to GPS in terms of a starting state, a goal state, and a
set of known operators. Thus, GPS will be a function of three arguments. For example,
a sample call might be:
GPS ( current_state , goal_state , list-of-operators)
Tracing of GPS function
1. Pick first goal from goal_state list.
2. Dr. Sadaf Gull / sadaf@biit.edu.pk Lecture#15,16
2. Check it in current_state list , it its already in current state the goal is achieved
3. If goal is not in current_state list then check it in add list, if found in add list of some
operator then check its preconditions list, We can apply an operator if we can achieve
all the preconditions, so if preconditions are not in current_state list then try to achieve
those preconditions first.
4. Once the preconditions have been achieved, apply an operator’s add and delete in
current_states list.
Example 1: Write GPS operators to achieve final state by moving blocks present in the
sequence as shown in initial state. Note that at one time only one block can be picked (only
from top).
block_ops = [
{"action":"Move block C on table",
"preconds":["Block C on A", "C-free"],
"add":["Block C on table", "A-free"],
"delete":["Block C on A"]},
{"action":"Move block A on table",
"preconds":["Block A on B","A-free"],
"add":["Block A on table", "B-free"],
"delete":["Block A on B"]},
{"action":"Move block B on C",
"preconds":["Block B on table", "B-free", "C-free"],
"add":["Block B on C"],
"delete":["Block B on table","C-free"]},
{"action":"Move block A on B",
"preconds":["Block A on table", "A-free","B-free"],
"add":["Block A on B"],
"delete":["Block A on table", "B-free"]}
]
gps(["Block B on table", "Block A on B", "Block C on A", "C-free"],
["Block C on table", "Block B on C", "Block A on B", "A-free"]
,block_ops )
TRACING:
0 Achieving: BLOCK C ON TABLE
A
B
C
Final State
C
A
B
Initial State
3. Dr. Sadaf Gull / sadaf@biit.edu.pk Lecture#15,16
1 Achieving: BLOCK C ON A
1 Achieved: BLOCK C ON A
1 Achieving: C-FREE
1 Achieved: C-FREE
0 Action: MOVE BLOCK C ON TABLE Achieved: BLOCK C ON TABLE
0 Achieving: BLOCK B ON C
1 Achieving: BLOCK B ON TABLE
1 Achieved: BLOCK B ON TABLE
1 Achieving: B-FREE
2 Achieving: BLOCK A ON B
2 Achieved: BLOCK A ON B
2 Achieving: A-FREE
2 Achieved: A-FREE
1 Action: MOVE BLOCK A ON TABLE Achieved: B-FREE
1 Achieving: C-FREE
1 Achieved: C-FREE
0 Action: MOVE BLOCK B ON C Achieved: BLOCK B ON C
0 Achieving: BLOCK A ON B
1 Achieving: BLOCK A ON TABLE
1 Achieved: BLOCK A ON TABLE
1 Achieving: A-FREE
1 Achieved: A-FREE
1 Achieving: B-FREE
1 Achieved: B-FREE
0 Action: MOVE BLOCK A ON B Achieved: BLOCK A ON B
0 Achieving: A-FREE
0 Achieved: A-FREE
EXECUTING MOVE BLOCK C ON TABLE
EXECUTING MOVE BLOCK A ON TABLE
EXECUTING MOVE BLOCK B ON C
EXECUTING MOVE BLOCK A ON B
Example 2: A Robot is standing outside a room, the door is closed and the lights are off,
Robot can walk. In its mind each action (operator) is store. The final goal is to turn on the
lights of the room. Robot will reason that to turn on the lights it has to move inside, but to
move inside the door should be opened. So in execution the first step would be the opening of
door. Then walking inside and then turning on the lights. We will see how this reasoning
process is done in the mind of the Robot, which is using GPS program. Consider following
function call of GPS.
gps ( [“standing-outside”, “door-closed”, “lights-off”], [“lights-on”], lights-ops)
lights_ops = [
{"action":"Turn ON lights",
"preconds":[" inside-room”, “lights-off "],
4. Dr. Sadaf Gull / sadaf@biit.edu.pk Lecture#15,16
"add":[" lights-on "],
"delete":[" lights-off"]},
{"action":"Walk inside the room",
"preconds":[" standing-outside” ,”door-open "],
"add":[" inside-room "],
"delete":[" standing-outside "]},
{"action":" Open the door ",
"preconds":["door-closed"],
"add":["door-opened"],
"delete":["door-closed"]}]
Tracing
Do as your assignment
Example 3: Driving son to school
sch_ops = [ {
"action": "drive son to school",
"preconds": ["son at home", "car works"],
"add": ["son at school"],
"delete": ["son at home"]
},
{ "action": "shop installs battery",
"preconds": ["car needs battery", "shop knows problem", "shop has
money"],
"add": ["car works"],
"delete": []
},
{ "action": "tell shop problem",
"preconds": ["in communication with shop"],
"add": ["shop knows problem"],
"delete": []
},
{ "action": "telephone shop",
"preconds": ["know phone number"],
"add": ["in communication with shop"],
"delete": []
},
{ "action": "look up number",
"preconds": ["have phone book"],
"add": ["know phone number"],
"delete": []
},
{ "action": "give shop money",
"preconds": ["have money"],
"add": ["shop has money"],
"delete": ["have money"]
}
]
5. Dr. Sadaf Gull / sadaf@biit.edu.pk Lecture#15,16
gps(["son at home", "have money", "have phone book", "car needs
battery"], ["son at school"],sch_ops )
Tracing
0 Achieving: SON AT SCHOOL
1 Achieving: SON AT HOME
1 Achieved: SON AT HOME
1 Achieving: CAR WORKS
2 Achieving: CAR NEEDS BATTERY
2 Achieved: CAR NEEDS BATTERY
2 Achieving: SHOP KNOWS PROBLEM
3 Achieving: IN COMMUNICATION WITH SHOP
4 Achieving: KNOW PHONE NUMBER
5 Achieving: HAVE PHONE BOOK
5 Achieved: HAVE PHONE BOOK
4 Action: LOOK UP NUMBER Achieved: KNOW PHONE NUMBER
3 Action: TELEPHONE SHOP Achieved: IN COMMUNICATION WITH SHOP
2 Action: TELL SHOP PROBLEM Achieved: SHOP KNOWS PROBLEM
2 Achieving: SHOP HAS MONEY
3 Achieving: HAVE MONEY
3 Achieved: HAVE MONEY
2 Action: GIVE SHOP MONEY Achieved: SHOP HAS MONEY
1 Action: SHOP INSTALLS BATTERY Achieved: CAR WORKS
0 Action: DRIVE SON TO SCHOOL Achieved: SON AT SCHOOL
EXECUTING LOOK UP NUMBER
EXECUTING TELEPHONE SHOP
EXECUTING TELL SHOP PROBLEM
EXECUTING GIVE SHOP MONEY
EXECUTING SHOP INSTALLS BATTERY
EXECUTING DRIVE SON TO SCHOOL
Example 4: Tower of Hanoi is a puzzle with three poles and three disks. Initial state of puzzle
stacked all three disks (whose sizes are in decreasing order) in pole one. The goal is to shift all
these disks from pole1 to pole 3 with following rules.
i. Only one disk can be moved at a time.
ii. No disk can be placed on top of a disk that is smaller than it.
Write down GPS operators using python to solve this puzzle. Also trace steps followed in its
solution.
The gps function call with lists of initial states and goal states is given below.
gps( [‘large-on-pole1’,‘medium-on-pole1’,‘small-on-
pole1’,‘pole2-empty’,‘pole3-empty’], [ ‘large-on-
pole3’,‘medium-on-pole3’,‘small-on-pole3’], tower_operators)
6. Dr. Sadaf Gull / sadaf@biit.edu.pk Lecture#15,16
tower_operators = [
{"action":"Move small on pole-3",
"preconditions":["small on pole-1", "pole-3 empty"],
"add":["small on pole-3"],
"delete":["small on pole-1",'pole-3 empty']},
{"action":"Move medium on pole-2",
"preconditions":["medium on pole-1", "small on pole-3", "pole-2
empty"],
"add":["medium on pole-2"],
"delete":["medium on pole-1","pole-2 empty"]},
{"action":"Move small on pole 2",
"preconditions":["small on pole-3", "medium on pole-2"],
"add":["small on pole-2","pole-3 empty"],
"delete":["small on pole-3"]},
{"action":"Move large on pole-3",
"preconditions":["large on pole-1","medium on pole-2", "small on
pole-2", "pole-3 empty"],
"add":["large on Pole-3", "pole-3 empty"],
"delete":["Block A on table", "B-free"]},
{"action": "Move small on pole-1",
"preconditions": ["small on pole-2", "pole-1 empty"],
"add": ["small on pole-1"],
"delete": ["small on pole-2", 'pole-1 empty']},
{"action": "Move medium on pole-3",
"preconditions": ["medium on pole-2", "large on pole-3", "small on
pole-1"],
"add": ["medium on pole-3"],
"delete": ["medium on pole-2"]},
{"action": "Move small on pole-3",
"preconditions": ["small on pole-1"],
"add": ["small on pole-3"],
"delete": ["small on pole-1"]},
Tracing
0 Achieving: LARGE ON POLE-3
0 Consider: MOVE LARGE ON POLE-3
1 Achieving: LARGE ON POLE-1
1 Achieved: LARGE ON POLE-1
1 Achieving: MEDIUM ON POLE-2
1 Consider: MOVE MEDIUM ON POLE-2
2 Achieving: MEDIUM ON POLE-1
2 Achieved: MEDIUM ON POLE-1
2 Achieving: SMALL ON POLE-3
2 Consider: MOVE SMALL ON POLE-3
7. Dr. Sadaf Gull / sadaf@biit.edu.pk Lecture#15,16
3 Achieving: SMALL ON POLE-1
3 Achieved: SMALL ON POLE-1
3 Achieving: POLE-3 EMPTY
3 Achieved: POLE-3 EMPTY
2 Action: MOVE SMALL ON POLE-3 Achieved: SMALL ON POLE-3
2 Achieving: POLE-2 EMPTY
2 Achieved: POLE-2 EMPTY
1 Action: MOVE MEDIUM ON POLE-2 Achieved: MEDIUM ON POLE-2
1 Achieving: SMALL ON POLE-2
1 Consider: MOVE SMALL ON POLE 2
2 Achieving: SMALL ON POLE-3
2 Achieved: SMALL ON POLE-3
2 Achieving: MEDIUM ON POLE-2
2 Achieved: MEDIUM ON POLE-2
1 Action: MOVE SMALL ON POLE 2 Achieved: SMALL ON POLE-2
1 Achieving: POLE-3 EMPTY
1 Achieved: POLE-3 EMPTY
0 Action: MOVE LARGE ON POLE-3 Achieved: LARGE ON POLE-3
0 Achieving: MEDIUM ON POLE-3
0 Consider: MOVE MEDIUM ON POLE-3
1 Achieving: MEDIUM ON POLE-2
1 Achieved: MEDIUM ON POLE-2
1 Achieving: LARGE ON POLE-3
1 Achieved: LARGE ON POLE-3
1 Achieving: SMALL ON POLE-1
1 Consider: MOVE SMALL ON POLE-1
2 Achieving: SMALL ON POLE-2
2 Achieved: SMALL ON POLE-2
2 Achieving: POLE-1 EMPTY
0 Achieving: SMALL ON POLE-3
GPS Code
def gps(initial_states, goal_states, operators):
prefix = 'EXECUTING '
for operator in operators:
operator['action'] = operator['action'].upper()
operator['add'].append(prefix + operator['action'])
operator['preconds'] = [pre.upper() for pre in
operator['preconds']]
operator['delete'] = [dlst.upper() for dlstin
operator['delete']]
operator['add'] = [add.upper() for add in operator['add']]
initial_states = [state.upper() for state in initial_states]
goal_states = [goal.upper() for goal in goal_states]
final_states = achieve_all(initial_states, operators, goal_states,
[])
if not final_states:
return None
actions = [state for state in final_statesif
state.startswith(prefix)]
8. Dr. Sadaf Gull / sadaf@biit.edu.pk Lecture#15,16
for a in actions:
print(a)
return actions
def achieve_all(states, ops, goals, goal_stack):
for goal in goals:
states = achieve(states, ops, goal, goal_stack)
if not states:
return None
for goal in goals:
if goal not in states:
return None
return states
def achieve(states, operators, goal, goal_stack):
print(len(goal_stack), 'Achieving: %s' % goal)
if goal in states:
print(len(goal_stack), 'Achieved: %s' % goal)
return states
if goal in goal_stack:
return None
for op in operators:
if goal not in op['add']:
continue
result = apply_operator(op, states, operators, goal, goal_stack)
if result:
return result
def apply_operator(operator, states, ops, goal, goal_stack):
result = achieve_all(states, ops, operator['preconds'], [goal] +
goal_stack)
if not result:
return None
print(len(goal_stack), 'Action: %s' % operator['action'], '
Achieved: %s' % goal)
add_list, delete_list = operator['add'], operator['delete']
return [state for state in result if state not in delete_list] +
add_list
-----------------------END -------------------