Ai ----------------assignment, Exercises of Artificial Intelligence

AIAIAIAIAIAIAIAIIAaiaiaiaiaiaiiaiaiaia

Typology: Exercises

2019/2020
On special offer
30 Points
Discount

Limited-time offer


Uploaded on 01/16/2020

hassam-khan007
hassam-khan007 🇵🇰

1

(1)

1 document

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Artificial Intelligence (CE-415) 2018-CE-165
Assignment#01
Artificial Intelligence(CE-415)
QUESTION#01:
(a)
WebCrawler Sample Implemented Using Crawler4j:Simple Web Crawler
with crawler4j.
A web crawler (also known in other terms like ants, automatic indexers, bots, web spiders, web robots or
web scutters) is an automated program, or script, that methodically scans or “crawls” through web pages
to create an index of the data it is set to look for. This process is called Web crawling or spidering.
Crawler4j is a java library that will extremely simplify the process of creating the web crawler.
Crawler4j is an open source web crawler for Java which provides a simple interface for crawling the
Web. Using it, you can setup a multi-threaded web crawler in few minutes.
https://code.google.com/p/crawler4j/downloads/list
Basically you have to create the crawler by extending the WebCrawler and create a controller for that. In
the crawler you have to override two basic method. They are,
shouldVisit - this method is called when visiting a given URl to determine whether it should be visited or
not.
visit - this method is called when the contents of the given URL is downloaded successfully. You can
easily access the URl and the contents of the page from this method.
Bellow is simple implementation of the shouldVisit method and it will access the pages in the same
domain as the added seed and will avoid from css, js and media files. First you can create a pattern to
avoid such types of pages.
Pattern filters = Pattern.compile(".*(\\.(css|js|bmp|gif|jpe?g" + "|png|tiff?|mid|mp2|mp3|mp4" + "|
wav|avi|mov|mpeg|ram|m4v|pdf" + "|rm|smil|wmv|swf|wma|zip|rar|gz))$");
Now we can override the shouldVisit method.
@Override
publicbooleanshouldVisit(WebURLurl) {
String href = url.getURL().toLowerCase();
return !filters.matcher(href).matches() &&href.startsWith("http://www.lankadeepa.lk/");}
pf3
pf4
pf5
pf8
pf9
Discount

On special offer

Partial preview of the text

Download Ai ----------------assignment and more Exercises Artificial Intelligence in PDF only on Docsity!

Assignment#

Artificial Intelligence(CE-415)

QUESTION#01:

(a)

WebCrawler Sample Implemented Using Crawler4j: Simple Web Crawler

with crawler4j. A web crawler (also known in other terms like ants, automatic indexers, bots, web spiders, web robots or web scutters) is an automated program, or script, that methodically scans or “crawls” through web pages to create an index of the data it is set to look for. This process is called Web crawling or spidering. Crawler4j is a java library that will extremely simplify the process of creating the web crawler. Crawler4j is an open source web crawler for Java which provides a simple interface for crawling the Web. Using it, you can setup a multi-threaded web crawler in few minutes. https://code.google.com/p/crawler4j/downloads/list Basically you have to create the crawler by extending the WebCrawler and create a controller for that. In the crawler you have to override two basic method. They are, shouldVisit - this method is called when visiting a given URl to determine whether it should be visited or not. visit - this method is called when the contents of the given URL is downloaded successfully. You can easily access the URl and the contents of the page from this method. Bellow is simple implementation of the shouldVisit method and it will access the pages in the same domain as the added seed and will avoid from css, js and media files. First you can create a pattern to avoid such types of pages. Pattern filters = Pattern.compile(".*(\.(css|js|bmp|gif|jpe?g" + "|png|tiff?|mid|mp2|mp3|mp4" + "| wav|avi|mov|mpeg|ram|m4v|pdf" + "|rm|smil|wmv|swf|wma|zip|rar|gz))$"); Now we can override the shouldVisit method. @Override publicbooleanshouldVisit(WebURLurl) { String href = url.getURL().toLowerCase(); return !filters.matcher(href).matches() &&href.startsWith("http://www.lankadeepa.lk/");}

You can override the visit method and print the details of the accessed pages. @Override public void visit(Page page) { String url = page.getWebURL().getURL(); System.out.println("Visited: " + url); if (page.getParseData() instanceofHtmlParseData) { HtmlParseDatahtmlParseData = (HtmlParseData) page.getParseData(); String text = htmlParseData.getText(); String html = htmlParseData.getHtml(); List links = htmlParseData.getOutgoingUrls(); System.out.println("Text length: " + text.length()); System.out.println("Html length: " + html.length()); System.out.println("Number of outgoing links: " + links.size()); } } Now you have to create the controller class. public class Controller { public static void main(String[] args) throws Exception { String rootFolder = "data/crowler"; intnumberOfCrawlers = 1; CrawlConfigconfig = new CrawlConfig(); config.setCrawlStorageFolder(rootFolder); config.setMaxPagesToFetch(4); config.setPolitenessDelay(1000); config.setMaxDepthOfCrawling(10); config.setProxyHost("cache.mrt.ac.lk"); config.setProxyPort(3128); PageFetcherpageFetcher = new PageFetcher(config); RobotstxtConfigrobotstxtConfig = new RobotstxtConfig(); RobotstxtServerrobotstxtServer = new RobotstxtServer(robotstxtConfig, pageFetcher); CrawlController controller = new CrawlController(config, pageFetcher, robotstxtServer); controller.addSeed("http://www.lankadeepa.lk/"); controller.start(Crawler.class, numberOfCrawlers); } }

  1. Create a source named "Local" and set the directory to where you cloned the repository (something like "c:\code\nuget-agent-api")
  2. Click Add then "OK" Using the package locally
  3. To use it you can open up your web app and choose >> tools >> Library Package Manager >> Package manager console
  4. In the console make sure that the source drop down is set to local
  5. Then type in "Install-Package NewRelic.Agent.Api"
  6. Hit enter QUESTION#03:

Figure 2: Chain Example

Answer:

Breadth First Search

State space:

As gave over the underlying state to the objective to be accomplished and locate the most limited

way.

Action:

Navigate the principal introductory chain and administrator needs nothing to change at this state

and totally cross every one of the connections, do interface next connection vertically left or

ideal to begin or end of connection. Push ahead to the following steel and after that it should

expel the second connection and do an indistinguishable thing from join the three connections

toward the end. Besides, changed the fasten as indicated by steel one. Moreover, no further

change required in chain three and 4 and associate steel 3 and 4 as needs be. This will

accomplish the objective.

A* Search Solution

State space:

As indicated by the above condition, we need to apply A* look on this issue.

Action:

Cross the connection one and compute the heuristic separation to the objective. At that point

administrator ought to interface the second connection, roll out the improvements, and ascertain

it once more. Administrator should expel the second connection of the second steel, at that point

figure the separation and further do likewise for rest of the chain interfaces and associate them to

end of the past connections. This will look through the briefest way utilizing A* seek.

QUESTION#04:

  1. InitialState : [[A->, D][D, E]]. Grid of 2x2 with agent in top left facing right and dirt in 2 squares  Operators : Move Forward, Suck, Turn Left, Turn Right, Switch Off  Goal Test : If there no dirt and is the agent switched off while sitting on the home square  Path Cost : +1 per action taken, -100 for piece of dirt sucked up, 1000 for not being on home square when switching off. To make this monotonic can make it 101 per action taken, 0 if sucking up dirt, 1100 for not being on home square
  2. Uniform Cost. You want to minimise path cost while reaching the goal
  3.  Set env = make_3x3() in vacuum_world.py and run using UniformCostSearch (UniformCost solves in 502, BreadthFirst in 624)  Set env = make_random_3x3() in vacuum_world.py and include search_cost in search.find_path() arguments  If the search cost is higher enough then it can be more effective to use a simpler agent  Can create a standard VacuumEnvironment() and apply search to test this. Search space expands by roughly (height * width) ^ actions where height and width are the number of

For more:https://studylib.net/doc/18715310/aima-chapter-3--solving-problems-by-searching

Q6) Imagine that you are a travel agent and a rather bother some customer wants you to

book a flight from New York to Los Angeles with XYZ Airlines. Even though you tell the

customer that XYZ does not have a direct flight from New York to Los Angeles, the

customer insist on only flying to XYZ

Looking at XYZ’s scheduled flights, you find the following:

NY – Chicago 1000 miles

Chicago - Denver 1000 miles

NY – Toronto 800 miles

NY – Denver 1900 miles

Toronto – Calgary 1500 miles

Toronto – Los Angeles 1800 miles

Toronto – Chicago 500 miles

Denver – Urbana 1000 miles

Denver – Houston 1500 miles

Houston – Los Angeles 1500 miles

Denver – Los Angeles 1000 miles

You quickly see that areaways from NY to LA on XYZ if you use connected flights.

a. Draw a Graph to represent the connections

b. Use Hill climbing to suggest the shortest route that the customer can opt for.

Answer:

a)

b)

By implementing Hill Climbing to the above graph