Está en la página 1de 17

Inteligencia Artificial

INDICE

2013-I

1) Animacin de Agentes---------------------------------------------------------------------2 a) Descripcin de la aplicacin---------------------------------------------------------2 b) Cdigo de Fuente----------------------------------------------------------------------2 c) Conclusiones----------------------------------------------------------------------------3 2) Variedad Colores---------------------------------------------------------------------------4 a) Descripcin de la aplicacin--------------------------------------------------------4 b) Cdigo de Fuente----------------------------------------------------------------------4 c) Conclusiones----------------------------------------------------------------------------5 3) La comunicacin----------------------------------------------------------------------------5 a) Descripcin de la aplicacin---------------------------------------------------------6 b) Cdigo de Fuente----------------------------------------------------------------------6 c) Conclusiones----------------------------------------------------------------------------7 4) Funcionamiento de molculas en de un motor--------------------------------------8 a) Descripcin de la aplicacin --------------------------------------------------------8 b) Cdigo de Fuente----------------------------------------------------------------------8 c) Conclusiones----------------------------------------------------------------------------9 5) Variedad Colores---------------------------------------------------------------------------10 a) Descripcin de la aplicacin--------------------------------------------------------10 b) Cdigo de Fuente----------------------------------------------------------------------10 c) Conclusiones----------------------------------------------------------------------------11 6) Figura geomtrica--------------------------------------------------------------------------12 a) Descripcin de la aplicacin--------------------------------------------------------12 b) Cdigo de Fuente---------------------------------------------------------------------12 c) Conclusiones---------------------------------------------------------------------------14 7) Ruta de un punto a otro------------------------------------------------------------------15 a) Descripcin de la aplicacin--------------------------------------------------------15 b) Cdigo de Fuente---------------------------------------------------------------------15

c) Conclusiones---------------------------------------------------------------------------17

Universidad Nacional de Ingeniera Especialidad: Ing. SISTEMAS

Pgina 1

Inteligencia Artificial
1. Animacin de Agentes 1.1. Descripcin de la aplicacin

2013-I

En esta aplicacin simularemos agentes (carros, barcos, animales, personas, etc.) la participacin de estos agentes ser de modo aleatorio como podemos ver en la grafica siguiente.

1.2.

Codigo de Fuente

breed [agents agent] ;; Repesenta los agentes globals [ next-agent-tick ;; Lama al Siguiente Agente ] to setup ca ;; Limpiar todo askpatcheswith [ pycor>-9 ] [ setpcolor88 ] ; askpatcheswith [ pycor=-9 ] [ setpcolor3 ] askpatcheswith [ pycor<-9 ] [ setpcolor4 ] ; Pintamos la pista set next-agent-tick 0 end to create-new-agent ;; Creamos nuevos Agentes ;; Reporte Colores let this-colour black create-agents 1 [ ifelse (notmember? type-of-agent ["any of the below""any of the motorway vehicles below""any of the railway vehicles below"]) [ setshape type-of-agent ] [ if (type-of-agent ="any of the below") [ setshapeone-of [ "airplane""ambulance""bike""bus""boat""car""car 2""cow""fish""mouse""person""sailboat""shark" "sheep""train""train freight engine""train passenger car""train passenger engine""truck""van" ] ] if (type-of-agent ="any of the motorway vehicles below")

Universidad Nacional de Ingeniera Especialidad: Ing. SISTEMAS

Pgina 2

Inteligencia Artificial

2013-I

[ setshapeone-of [ "ambulance""bus""car""car 2""truck""van" ] ] if (type-of-agent ="any of the railway vehicles below") [ setshapeone-of [ "train""train freight engine""train passenger car""train passenger engine" ] ] ] setheading90 setsize size-of-agent setxcor (-max-pxcor) setycor y-position ] end to animate-agents ; Movemos la pantalla a la derecha o izquierda let colour black if (ticks= next-agent-tick) [ create-new-agent set next-agent-tick ticks+random next-agent-random-tick-interval + minimum-gap ; Creamos un carro aparte ] ask agents [ if (xcor+1>max-pxcor) [ die ] ; Movemos el Agentes a la pantalla setxcorxcor+1; Movemos el agente a la derecha ] tick end

1.3.

Conclusiones

Este modelo de simulacin con el programa de NetLogo nos ayuda a realizar interacciones con distintos agentes que nos rodean en la vida diaria.

Universidad Nacional de Ingeniera Especialidad: Ing. SISTEMAS

Pgina 3

Inteligencia Artificial
2. Variedad Colores 2.1. Descripcin de la aplicacin

2013-I

En esta aplicacin simularemos la variedad de colores que nos pueden salir combinado colores bsicos como mostramos en la grafica siguiente.

2.2.

Cdigo de Fuente

to setup ca ;; Preparamos el color Blanco ask patches [ set pcolor white ] ;; Pintamos los 139 colores ask patches with [(pxcor >= 0) and (pxcor <= 9) and (pycor <= 0) and (pycor >= -13)] [ set pcolor -10 * pycor + pxcor set plabel int pcolor ] ;; Pintamos la columnas de blanco ask patches with [(pxcor = 10) and (pycor <= 0) and (pycor >= -13)] [ set pcolor -10 * pycor + 9.9 ] ;; Pintamos todas las columnas de los patch label ask patches with [(pxcor = 11) and (pycor <= 0) and (pycor >= -13)] [ set plabel word precision (-10 * pycor + 9.9) 4 " "] ;; Pintamos las claves de la izquierda

Universidad Nacional de Ingeniera Especialidad: Ing. SISTEMAS

Pgina 4

Inteligencia Artificial

2013-I

ask patches with [(pxcor = -2) and (pycor <= 0)] [ if pycor = int (blue / -10) [ set plabel "blue" ] if pycor = int (brown / -10) [ set plabel "brown" ] if pycor = int (cyan / -10) [ set plabel "cyan" ] if pycor = int (gray / -10) [ set plabel "gray" ] if pycor = int (green / -10) [ set plabel "green" ] if pycor = int (lime / -10) [ set plabel "lime" ] if pycor = int (magenta / -10) [ set plabel "magenta" ] if pycor = int (orange / -10) [ set plabel "orange" ] if pycor = int (pink / -10) [ set plabel "pink" ] if pycor = int (red / -10) [ set plabel "red" ] if pycor = int (sky / -10) [ set plabel "sky" ] if pycor = int (turquoise / -10) [ set plabel "turquoise" ] if pycor = int (violet / -10) [ set plabel "violet" ] if pycor = int (yellow / -10) [ set plabel "yellow" ] set plabel (word plabel " = " (-10 * pycor + 5) " ") ] ;; Pintamos de blanco y negro todas las columnas ask patches with [pycor = 1] [ if pxcor = 0 [ set plabel "black = 0" ] if pxcor = 11 [ set plabel "white = 9.9 " ] ] ;; hacemos todos los patch label visible ask patches [ ifelse pcolor mod 10 >= 4 [ set plabel-color black ] [ set plabel-color white ] ] end

2.3.

Conclusiones

Como podemos observar la grafica anterior simulada nos permite obtener los 139 colores que son visibles por el ser humano

Universidad Nacional de Ingeniera Especialidad: Ing. SISTEMAS

Pgina 5

Inteligencia Artificial
3. La comunicacin 3.1. Descripcin de la aplicacin

2013-I

El grafico siguiente nos permite simular la presencia de puntos aleatorios azules en un primer momento que se tratan de comunicar luego con el paso del tiempo se van incrementando los puntos aleatorios de color rojo para que estos establezcan una comunicacin, de cada combinacin bajo la siguiente regla. Azul vs. Azul Resultado Azul Azul vs. Rojo Resultado Rojo Rojo vs. Rojo Resultado Rojo

3.2.

Cdigo de Fuente
;; Mensaje muestra la cantidad de interacciones de la

turtles-own [ message? color rojo

to setup clear-all crt 500 [ set message? false setxy random-xcor random-ycor ] ask one-of turtles [ set message? true ] 1 de la cantidad de interacciones ask turtles [ recolor ] end to go

;; Aca nos da el mensaje

Universidad Nacional de Ingeniera Especialidad: Ing. SISTEMAS

Pgina 6

Inteligencia Artificial
ask turtles [ move ] ask turtles [ communicate ] ask turtles [ recolor ] tick end ;; Posision random to move ;; Proceso del movimiento fd random 4 ;; vuelta en random amount between -40 and 40 degrees, ;; combina en el medio turn at 0 rt random 40 lt random 40 end ;; lo principal del procedimiento! to communicate ;; Procediminto if any? other turtles-here with [message?] [ set message? true ] end ; color con mensaje rojo and cambiamos con el mensaje blue to recolor ;; Proceso del color ifelse message? [ set color red ] [ set color blue ] end

2013-I

3.3.

Conclusiones

Como podemos notar en la grafica del simulador anterior aplicando la regla: Azul vs. Azul Resultado Azul Azul vs. Rojo Resultado Rojo Rojo vs. Rojo Resultado Rojo Al final del proceso de simulacin los puntos de color azul desaparecen y se llena de puntos rojos el simulador

Universidad Nacional de Ingeniera Especialidad: Ing. SISTEMAS

Pgina 7

Inteligencia Artificial
4. Funcionamiento de molculas en de un motor 4.1. Descripcin de la aplicacin

2013-I

Este simulador nos muestra el comportamiento de la estructura interna de un motor.

4.2.

Cdigo de Fuente

flashes-own [birthday] particles-own [ speed mass energy ;; particle info momentum-difference ;; used to calculate pressure from wall hits last-collision ;; used to prevent particles from colliding multiple times to setup ca set-default-shape particles "circle" set-default-shape flashes "plane" set max-tick-delta 0.1073 ;; box has constant size. set raw-width round (0.01 * box-width * max-pxcor) set raw-height round (0.01 * box-height * max-pycor) set piston-height raw-height make-box make-piston set piston-vel 0 set gravity 0.125 ;;; 19 patches of wall space on the inside of the box set length-horizontal-surface ( 2 * (raw-height - 1) + 1) set length-vertical-surface (piston-height) make-box

Universidad Nacional de Ingeniera Especialidad: Ing. SISTEMAS

Pgina 8

Inteligencia Artificial

2013-I

make-particles set pressure-history [0 0 0] ;; plotted pressure will be averaged over the past 3 entries update-variables set init-avg-speed avg-speed set init-avg-energy avg-energy setup-plots do-plotting end to go if piston-height < 3 [ user-message "The piston reached the bottom of the chamber. The simulation will stop." stop ] if piston-height >= 2 * raw-height - 1 [ user-message "The piston reached the top of the chamber. The simulation will stop." stop ] ask particles [ bounce ] ask particles [ move ] ask particles [ check-for-collision ] move-piston tick-advance tick-delta if floor ticks > floor (ticks - tick-delta) [ calculate-pressure update-variables do-plotting ] calculate-tick-delta ;; we check for pcolor = black to make sure flashes that are left behind by the piston die ask flashes with [ticks - birthday > 0.4 or pcolor = black] [ die ] display end to update-variables ;; particle variables set medium count particles with [color = green] set slow count particles with [color = blue] set fast count particles with [color = red] set avg-speed mean [speed] of particles set avg-energy mean [energy] of particles set tot-particle-energy sum [energy] of particles set piston-energy (piston-kinetic-energy + piston-potential-energy) end

4.3.

Conclusiones

Este simulador es de gran importancia En la actualidad ya que permite aumentar los niveles de eficiencia en los motores .

Universidad Nacional de Ingeniera Especialidad: Ing. SISTEMAS

Pgina 9

Inteligencia Artificial
5. Variedad Colores 5.1. Descripcin de la aplicacin El siguiente simulador muestra las posibles salidas de una explosin bajo el efecto de de la gravedad.

2013-I

5.2.

Cdigo de Fuente

turtles-own [ velocity-x velocity-y force-accumulator-x force-accumulator-y ]

; ; ; ;

particle velocity in particle velocity in force exerted in the force exerted in the

the x axis the y axis x axis y axis

to setup clear-all ask patch 0 (max-pycor / 2) [ sprout num-particles [ set velocity-x 10 - (random-float 20) ; initial x velocity set velocity-y 10 - (random-float 20) ; initial y velocity pen-down ] ] end to go if not any? turtles [ stop ] compute-forces ; calculate the forces and add them to the accumulator

Universidad Nacional de Ingeniera Especialidad: Ing. SISTEMAS

Pgina 10

Inteligencia Artificial
apply-forces the

2013-I

; calculate the new location and speed by multiplying

; forces by the step-size tick-advance step-size display end ; calculate and sum all the forces exerted on the particles to compute-forces ask turtles [ ; clear force accumulators set force-accumulator-x 0 set force-accumulator-y 0 ; calculate forces apply-gravity ] end ; updates the accumulator with the gravity force to apply-gravity ;; turtle procedure set force-accumulator-y force-accumulator-y - gravity-constant end ; calculates the position of the particles at each step to apply-forces ask turtles [ ; calculate the new velocity of the particle set velocity-x velocity-x + (force-accumulator-x * step-size) set velocity-y velocity-y + (force-accumulator-y * step-size) ; calculate the displacement of the particle let step-x velocity-x * step-size let step-y velocity-y * step-size ;; if the turtle tries to leave the world let it die if patch-at step-x step-y = nobody [ die ] ;; if the turtle does not go out of bounds ;; add the displacement to the current position let new-x xcor + step-x let new-y ycor + step-y facexy new-x new-y setxy new-x new-y ] end

5.3.

Conclusiones

Este simulador nos muestra el posible comportamiento de las bombardas de los juegos artificiales, asi tambin la explosin de un cuete ajo el efecto de la gravedad

Universidad Nacional de Ingeniera Especialidad: Ing. SISTEMAS

Pgina 11

Inteligencia Artificial
6. Figura geomtrica 6.1. Descripcin de la aplicacin

2013-I

Mediante el siguiente simulador se muestra todas las posibles graficas que se puede construir con 5 puntos que tenemos como base.

6.2.
globals [ level ]

Cdigo de Fuente

;; determines how many nodes you have to untangle; ;; the formula is below

to setup clear-all set-default-shape turtles "circle" ask patches [ set pcolor white ] set level starting-level setup-level end

;; plain white background

to setup-level reset-ticks ;; use tick counter as a move counter clear-turtles ;; when the turtles die, the links connecting them die too ;; create nodes and position them randomly create-turtles 4 + level [ set color blue setxy random-xcor random-ycor ] ;; Now we need to make some links. We have to be careful that

Universidad Nacional de Ingeniera Especialidad: Ing. SISTEMAS

Pgina 12

Inteligencia Artificial

2013-I

;; the resulting graph has a solution. Probably there are lots ;; of ways this could be done, but this was the simplest way we ;; could think of. ;; First make a bunch of links at random. while [count links < count turtles] [ ask one-of turtles [ ask one-of other turtles [ attempt-link ] ] ] ;; Then fill in all remaining allowable links. ask turtles [ ask other turtles [ attempt-link ] ] ;; Now we have a graph which we know is solvable, ;; because the current layout is a solution. ;; Time to scramble the nodes around! while [solved?] [ scramble ] display end to attempt-link ;; link procedure ;; note that if the link already exists, nothing happens create-link-with myself [ if any-intersections? [ die ] ] end to scramble ;; The turtles agentset is always in random order, ;; so this makes a random layout. layout-circle turtles (world-width / 2 - 1) end ;; This procedure lets us find the next turtle, ;; or the turtle two over, and so on. to-report turtle-plus [n] ;; turtle procedure report turtle ((who + n) mod count turtles) end to go if mouse-down? [ ;; find the closest node let grabbed min-one-of turtles [distancexy mouse-xcor mouse-ycor] ;; loop until the mouse button is released while [mouse-down?] [ ask grabbed [ setxy mouse-xcor mouse-ycor ] display ] ;; use tick counter as a move counter tick ;; check if the level is solved if solved? [ user-message "You rock. Now try this..." set level level + 1 setup-level ] ] end to-report solved?

Universidad Nacional de Ingeniera Especialidad: Ing. SISTEMAS

Pgina 13

Inteligencia Artificial
report all? links [not any-intersections?] end to-report any-intersections? ;; link procedure report any? other links with [crossed? self myself] end to-report crossed? [link-a link-b] ;; store nodes in variables for easy access let a1 [end1] of link-a let a2 [end2] of link-a let b1 [end1] of link-b let b2 [end2] of link-b let nodes (turtle-set a1 a2 b1 b2) ;; if the links share a node, they don't cross if 4 > count nodes [ report false ] ;; but if two nodes are on top of each other, we will say ;; the links do cross (so you can't cheat that way) if 4 > length remove-duplicates [list xcor ycor] of nodes [ report true ] ;; if the ends of link-a are on opposite sides of link-b, ;; and the ends of link-b are on opposite sides of link-a, ;; then the links cross report [subtract-headings towards a2 towards b1 < 0 xor subtract-headings towards a2 towards b2 < 0] of a1 and [subtract-headings towards b2 towards a1 < 0 xor subtract-headings towards b2 towards a2 < 0] of b1 end

2013-I

6.3.

Conclusiones

Este simulador es de gran ayuda para los estudiantes de geometra principalmente pero lamentablemente no se implanta en los colegios.

Universidad Nacional de Ingeniera Especialidad: Ing. SISTEMAS

Pgina 14

Inteligencia Artificial
7. Ruta de un punto a otro 7.1. Descripcin de la aplicacin

2013-I

Mediante el grafico siguiente muestra como ir de un punto a otro por la ruta mas corta en un periodo de tiempo

7.2.

Cdigo de Fuente

breed [ leaders leader ] breed [ followers follower ] globals [ nest-x nest-y food-x food-y leader-heading ] ;; location of center of nest ;; location of center of food ;; heading of the leader ant

to setup ca set-default-shape turtles "bug" set nest-x 10 + min-pxcor ;; set up nest and food locations set nest-y 0 set food-x max-pxcor - 10 set food-y 0 ;; draw the nest in brown by stamping a circular ;; brown turtle ask patch nest-x nest-y [ sprout 1 [

Universidad Nacional de Ingeniera Especialidad: Ing. SISTEMAS

Pgina 15

Inteligencia Artificial
set color brown set shape "circle" set size 10 stamp die ] ] ;; draw the nest in orange by stamping a circular ;; orange turtle ask patch food-x food-y [ sprout 1 [ set color orange set shape "circle" set size 10 stamp die ] ] create-leaders 1 [ set color red ;; red set size 2 wiggle 50 ] ;; out with a random heading create-followers (num-ants - 1) [ set size 2 set color yellow ] ;; yellow ask turtles [ setxy nest-x nest-y ;; out at the nest set heading 90 ] ask turtle (num-ants - 1) [ set color blue ;; set pen-size 2 pd ] ;; trail ask leaders [ set pen-size 2 pd ] ;; leaves a trail set leader-heading [heading] of one-of leaders end to go if all? turtles [xcor >= food-x] [ stop ] ask leaders wiggles and moves [ wiggle leader-wiggle-angle correct-path if (xcor > (food-x - 5 )) straight for food, if it is close [ facexy food-x food-y ] if xcor < food-x you're at or past the food [ fd 0.5 ] ] ask followers [ face turtle (who - 1) follow the ant ahead of them

2013-I

leader ant is ...and starts

middle ants are start the ants

last ant is blue ...and leaves a

the leader also

;; the leader ant

;; leader heads ;; do nothing if

;; follower ants

Universidad Nacional de Ingeniera Especialidad: Ing. SISTEMAS

Pgina 16

Inteligencia Artificial
if time-to-start? and (xcor < food-x) a bit before leaving nest [ fd 0.5 ] ] set leader-heading [heading] of one-of leaders tick end

2013-I
;; followers wait

;; turtle procedure; wiggle a random amount, averaging zero turn to wiggle [angle] rt random-float angle lt random-float angle end ;; turtle procedure to correct-path ifelse heading > 180 [ rt 180 ] [ if patch-at 0 -5 = nobody [ rt 100 ] if patch-at 0 5 = nobody [ lt 100 ] ] end ;; turtle reporter; if true, then the ant is authorized to move out of the nest to-report time-to-start? report ([xcor] of (turtle (who - 1))) > (nest-x + start-delay + random start-delay ) end

7.3.

Conclusiones

Como podemos observar en el simulador anterior de la vida real para ir de un punto a otro sabemos como llegar al otro punto pero mas no cual es la ruta mas corta en la grafica anterior se nota que es una especie de parbola como sucede en la vida real pero matemticamente la ruta mas corta seria una recta pero no se cumple en la realidad.

Universidad Nacional de Ingeniera Especialidad: Ing. SISTEMAS

Pgina 17