You are on page 1of 155

Al Application

Programming


M.Tim Jones

CHARLES RIVER MEDIA, INC.


Hingham, Massachusetts

004.8
32.813
42

42

. .
/ .
; . . . . - .: , 2004. - 312 : .

ISBN 5-94074-275-0


(),
.
,
. m
OCHI

, 1
,

- , ,
. , , ,
. .
,
. , , . ,
.
.

Copyright 2003 by CHARLIES RIVER MEDIA INC.


Translation Copyright 2004 by DMK PRESS: All rights reserved.
. <

:

ISBN 1-58450-278-9 (.)


ISBN 5-94074-275-0 (.)

Copyright 2003 by CHARLIES RIVER MEDIA


,
, . , 2004

1.



15
15
16
16
16

, 1940-
, 1950-
, 1960-
, 1970-
, 1980-
, 1990-

16
17
18
19
19
20
21
21
21
21
22
22

22
23
24

2.






25
25
25
'.

26
26
26
27
28
28


3.

28
29
30
30
30

32
38
40
40
40
40
40

41
41
41
43



ART1

43
43
44

ART1

ART1
ART1

ART'
ART1


ART1

44
47
48

48
48
48
49
49
49

SQ
59
59
60
61
gl
62

| |

4.

63

63
65






Alpha (a)/Beta ()
Rho(p)

65
67
67"
67
67
68
68

68
71
71
80
82
-.

5.

82
82
82

83
83
83

85

85


SLP

86
87
88

90
90
91
94
96
98
98
100

6.

. 10
110
110
110
111
112
112
112

113
114
114
115
116

116
117
118

120
120
120
120
121
121
121
124

134

136
136
136
136
137
137
138
138
138
139
139
139
140

||||

7.

141

141
141
142
142
142
143
145
147
147
147
147
151
171

173

173

174

174

8. ,

175

175
175
176
176
177

177
177
177
178
178
178
179
179
181
181
182
185

:||| ! )

9.


10.

207
207
208
208
209

210
210
211
212
213
215
216
216
216
217
217
219
219
221
223
224
225
226
226
226
227
227
228
229
229
230
231
231
231

240
241
241
241

11. ,



,


Web-
Web-

Web-



243
243
243
245
247
248
248
249
249
252
272
279
295
296
296
297

'

12.

298

298

299

CYC



Internet

299
300
300
301
302
303

.

..:

305
305
305
305
305


(fill) (Megan),
(Elise) (). .

306
306
306
307
307
307
307

. ,
.
(Alan Turing), (John McCarthy), (Arthur
Samuel), . (N. Metropolis), (Gail Carpenter), (Stephen Grossberg), (Marco Dorigo), (David Rumelhart), (Geoffrey Hinton),
Ghn van Neumann), (Donald Hebbs),
(TcuvO Kohonen), (John Hopfield), (Warren
McCulloch), (Walter Pitts), (Marvin Minski),
(Seymour Papert), (John Holland),
(John Koza), (Thomas Back), (Bruce MacLennan),
(Patrick Winston), (Charles Forgy),
(Lotfi Zadeh), (Rodney Brooks), (Andrey Markov),
(James Baker), (Doug Lenat),
(Claud Shannon) (Alan Kay).
(Dan Klein)' .

( ) ,
, ,
.
, (- ),
.

, , .
. , . , , , , , .
. , .
, ,


. ,

.
- , .
, .
mtj@mtjones.com.

,
:

;
,
;
;
(, 1.1).
* www.dmk.ru.

1.

.

.


, (Artificial Intelligence - AI),
, , . , , .
,
. , . , .
,
. , .
. ,
.
, ,
, . ,
, , - . ,
,
. (Rodney Brooks) .
, .
(Almost Implemented), .



- ,
. (Strong
AI) , , . ,
.
(Weak AI) .
* . , .


, . , 1960- !- ,
. .
.
,
.
. , , , , . , , .
. , , .

9.


. , :
.
, 1940- ,
(Stottler Henke, 2002).
, 1940-
. , . 1940 .

E I I H H H I Q
- (Robinson).
,
(Enigma).
, (Heath Robinson).
, (Colossus).
. 1945 . . (Dr. John W. Mauchly) . . Q. P. Eckert, Jr.)
, ENIAC.
.
(Walter
Pitts) (Warren McCulloch) 1945 .,
.
.
(Norbert Wiener) , . ,
- .
1949 . (Donald Hebbs) . ( *) , .
,
.

, 1950-
1950- . (Alan
Turing) (
) . , , .
, , , . ( ), .
1950- . . ,
, . ,
Logic Theorist ( -
(Newel!), (Simon) (Shaw)) General Problem Solver ( ), . , 1950-
2 -409


,
.
1950- . . , IPL,
, Logic Theorist. IPL

LISP. LISP 1950- IPL,
. LISP
(MIT). ,
.
. 1956 .
, . : , ,
,
. , ,
, ,
, , <?.
, .
1950- MIT , .

, 1960-
1960- . , ,
. , ,
, .
: : !-
(Mortimer Taub) (Hubert
and Stuart Dreyfus).
1960- ,
. , , Blocks Microworld Projects MIT;
SHRDLU (Terry Wmograd). ,
, .
1960- "
. , , *
(Shakey), .
1960-, ,
: ^.

,
.
, 1960- 2001 .
HAL, , ,
, .

, 1970-
1970- . , . - . ,
MIT, . . , .
(AM) - EURISKQ . AM ,

. EURISKO, ,
AM , , , .
1970- . , (Lotfi Zadeh) 1960-.

(Queen Mary),
.
1970- . (Prolog - ).
, (
) . , LISP
.
1970-. . , , (Luigi Villa) .
.

, 1980-
1980- . , , , 400 .
1986 .
LISP , , LISP-, ,
.

, ,


, , . ,
. , XCON Digital
Equipment Corporation 10000 , .
1980- . . , .
, 1980- , .
.
1980- . , (
, ), , (
, ). , .
, 1990-
1990- . . , , , ,
, .
(
Stottler Henke, 2002):
;
;
;
;
*- ;
.
1997 . Deep Blue (
). ,
.
1990- . 60 .
. Deep Space I (DS1), 12- ,
. DS1 Remote Agent, .
. Remote Agent ,
,
.

1]


, . 1.1 . , , .
1.1. Hanpaej

( Al FAQ)

,




, ci
,
, ,

,

. ,
.

, .


(Alan Turing)
, , , . - , , , . ,
,
.
.


(John McCarthy) . MIT,

1111
, 1956 ( ).
LISP, .
,
.


(Marvin Minsky) , . MIT,
1958 .
,
, . , , . .

(Arthur Samuel, 1901-1990) . .' , .
, 1957 . ,
. ,
() .
.

,
. , , , ?
, ? , ,
? , ,
,
?
, , ,
. , , ?
? 2001 *
.
,
, ,


, .
, ,
, ?


,
, .
, ,
.
. .
2 , { ). N-.
3 ( ART)
. , .
4 . .
5 ,
.
.
6 - . , .
7
, -^ .
.
8 . , .
9
. ,
.
10 .
, .


11 , . ,
.
, 12 .


1. Stottler Henke. . (History of AI, 2002). http://
www.sh ai .com/ai_general /history.htm.
2. . :
(Waginan M.
Scientific Discovery Processes in Humans and Computers: Theory and Research
in Psychology and Artificial Intelligence. - Westport, Conn.: Praeger Publishers,
2000).
3. . (Kantrowitz M. The AI
Frequently Asked Questions, 2002). (Ric Crabbe)
(Amit Dubey). http://www.faqs.org/faqs/
4. . : (Crevier D. AI: The
Tumultuous History of the Search for Artificial Intelligence. - New York: Basic
Books, 1993).
5. . : (Kurzweil R. The Age of Spiritual Machines: When Computers
Exceed Human Intelligence. - New York: Viking, 1999).
6. . (McCarthy J.). Web- ,
http:/ /www- formal. stanfo rd. eou/j me.
7. . : (McCarthy J.
Arthur Samuel, Pioneer in Machine Learning). h t t p : / /
www-db.stanford.edu/pub/vov/museum/samuel.html.
8. ., ., ., . .
(McCarty J., Minsky M., Rochester N., Shannon . . A Proposal for the
Darmouth Research Project on Artificial Intelligence, 1955). http: //www.foiTnal.stanford.edu/imc /history /dartmouth /dartmouth.html.
9. M. (Minsky M). Web- MIT, http://web.mediamit.edu/-minsky.
10. ., . : (Minsky M., Papert S. Perceptrons: An Introduction to Computational
Geometry. - Cambridge, Mass.: MIT Press, 1969).
11. . : (Taube
. Computers and Common Sense: The Myth of Thinking Machines, Columbia
University Press, 1961).

2.
, ,
(Simulated annealing). , . - , . ,
, . , , ,
.


,
. , ,
. ,
.
, . . , . -

. , ,
- .
, .
,
. , . , .
.


, . (. 2.1).

"

. 2.1-


.
(Current solution). ,
, , ,
. ,
.

IMKHHES

, , (). , .
, . , .
,
. - (
).


. - , , - , .
, (,
, ).
. , (
), .
, , 1 , , . 2.1 (, ,
):
(6> - (-8/)

(2.1)

. 2.2. ( 60 *) , . , .


?
, . , ;
. -*
, , -.
.




(Working solutio ).

. 2.2.

1|

. . (. 2.2):
,-,

(2.2)

4. 2.1, :
- (-4/2) - 0,135335.
, . . , .


, . N ( NQP) - N
NxN , (. 2.3).

. , .

.
. ,
.


, . , (
) , . , , .
, 50, 10.
. , 20. ,
. :
10.
20.
(
) 10. 50 2.1, :
- (-10/50) = 0,818731.
, ,
.
, 2, :
3.
7.

IE]

. .
-' , . ,
0.

. 2.3. 92 8

1111

8 1850 . (Carl Friedrich Gaub). ( ) .


(1987), ^- (1989), (1992) . 1990 .
(Rok Sosic) (Jun Gu) 3000000
.

() N :
.
(. 2.3),
. ,
.
, N (. 2.4).
. , . 2.4
1 5, , noi
.
. , , .
1 N . ( ). , -,
.
, , , -;
. -]
.

, . , , ( ).

30 |
, (|
2.2). 0,98. , ]
, -^j
- .
100 .
.

, N ,
<% www.dmk.ru. /software/ch2/emsapop
, :
N ( N 80).

. 2.4. N

|||


,
>
N .
, (. 2.1).
2.1.
#define MAX_LENGTH 30
typedef

int

solutionType[MAX_LENGTH];

30.0
0.5
0.98
100

s o l u t i o n T y p e - .
MAX_LENGTH ( 30 ). MAX_LENGTH (
50 ),
.
memberType, , .
2.1 . ]
INITIAL_TEMPERATORE FINALJTEMPERATURE , ALPHA . STEPS_PER_CHAMGE ,
.
. 2.2
.
:
2.2.
>id tweakSolutii i( memberType *membei
.nt temp,

x = getRand(MAX_LENGTH];
do {
= getRand(MAX_LENGTH);
} while (x == y ] ;

oid initializeSolution< memberType *member )


{
int i,/* */
for (i = 0 ; i < MAX_LEMGTH ; i++) {
member->solution[i] = i;
/*
for (i = 0 ; i < MAX_LENGTH ; i++) {
tweakSolution( member );

solutionType s o l u t i o n ;
f l o a t energy,} memberType;
/* */
Idefine INITIAL_TEMPERATURE
#define FINAL_TEMPERATURE
#define ALPHA
#define STEPS_PER_CHANGE

temp = member->solution[x];
member~>solution[x] member>solutn.Qn[y] j
member->solution[y] = temp;

i n i t i a l i z e S o l u t i o n , .
. .
t w e a k S o l u t i o n . t w e a k S o l u t i o n , , .
c o m p u t e E n e r g y . ,
( 2 3}
2.3.
void computeEnergy( memberType *member )
char board[MAX_LENGTH][MAX_LENGTH];
int conflicts;
const int dx[4] = {-1, 1, - 1 , 1};
const int dy[4] = (-1, 1, 1, -1};
/* */
bzero( (void *)board, MAX_LENGTH * MAX_LENGTH );
for (i = 0 ; i < MAX_LENGTH ; i++) {
board[i][member->solution[i]] = ' Q 1 ;

I H H

H H H I H I 1

, , - e m i t S o l u t i o n . .
( 2.5).
2.5.

conflicts = ,for (i = 0 ; i < MAX_LENGTH ; i++)


/* ; !
*
*/
/* */
for (j - 0 ; j < 4 ,- j++) {
tempx =
; tempy
while(l ) {
tempx += dx[j]; te
if ((tempx < 0) ! 1
{tempy < 0)

void e m i t S o l u t i o n ( memberType *member )


{
Char board[MAX_LENGTH][MAX_LENGTHJ;
i n t x, y;
bzerot (void *)board, MAX_LENGTH * MAX_LENGTH );
MAX_LENGTH) I I
>= MAX_LENGTH)) b r e a k ;

for (x = 0 ; x < MAX_LENGTH ; x++) {


board[x][member->solution[x]] = 'Q';
printf("board:\n");
f o r (y = 0 ; < MAX_LENGTH ; y++) {
for (x = 0 ; x < MAX_LENGTH ; x++) (
if ( b o a r d [ x ] [ y ] == 'Q 1 ) p r i n t f { " Q " ) ;
else p r i n t f ( " . );
}
p r i n t f ( n \ n n ) ,)
printf<*\n\a");

member->i
, .
, . dx dy.
.
dx = - i , a d y = - 1 , . , dx = 1, dy = - 1 , .
( ), , . , .
.
. ( 2:1),
memberType. c o p y S o l u t i o n
memberType ( 2.4).
2.4.
v o i d c o p y S o l u t i o n ( memberType * d e s t , memberType * s r c )

MAX_LEKGTH ;

}
e m i t S o l u t i o n
( - , - ). (Q , . - ).
, m a i n ()
( 2.6).
2.6.

f l o a t tempei
memberType
FILE * f p ;

srand(time(NULL));

= INITTALJTEMPERATURE;
working, b e s t ;


energy = %f\n 11, best.energy) ;

p r intfCB e s t

while (temperature > FINAL_TEMPERATURE) {

mperatu

= ALPHA;

fclo se(fp) ;
if ( solutio n)
dtSolut

/* */
for (step = 0 ; step < STEPS_PER__CHANGE ; step++) {

bbest );

i 0;

computeEnergy( ^working );
if (working.energy <= current.energy) {
useNew = 1;
} else {
m d () ;
fl.
float delta = working.energy - current.energy;
float calc = exp(-delta/temperature);
if (calc > test) {
accepted++;
useNew = 1;

if (useNew) {
UseHew - 0;
if (current.energy < best.energy) {
copySolutionl sbest, ^current );

} else {
copySol

, accepted);

, 2.6,
, . 2.1. ( )
c u r r e n t
compute Energy.
, .
,
.
.
-.

.
- t w e a k S o l u t i o n . , . , .
2.1 ( ).
, .
. ,
, . 0 1, 2.1. ( 2.1 ), .
, working, ,
.
,
. , .
- ( ).
( 2.2),
. ALPHA .

, b e s t , ( , s o l u t i o n ) .
, , ,
b e s t .


. 100, 30. (. 2.5).

, - ( 2.1). ,
. , . ,
. ( - ), .
40 ( . 2.5)
. 2.6.

. 2.5. 40
, 100 0, . 2.2. ,

. 2.6. 40

ESBHHUIIII


, . , , .


, .
(Graham Kendall), , .
.
, ,
( ). , .


, , , ,
, . 2.1 0,5.
, .



. . 2.5
.
. , .
Web- (Brian Luke) *.



.
, , .
, ,
. ( 2.1) 100 . ,
, .


, . :
;
;
D ;
Q ;
;
;
.

, .
.

. .
. . N . , ,

, .


1. . (Gallant S. Neural Network Learning. Cambridge, Mass.: MIT Press, 1994).
2. . (Dowsland . Simulated Annealing // Modern Heuristic Techniques for Combinatorial Problems, Colin
Reeves (ed.). - New York: McGraw-Hill, 1995).
3. ., . , (Carpenter G., Grossberg S. A Massively Parallel Architecture for a Self-Organizing Neural Pattern
Recognition Machine // Computer Vision, Graphics and Image Processing,
1987).
4. . (Kendall G. Simulated Annealing, 2002). http://wwwxs.nott.ac.uk/-gxk/aim/notes/
Simuiatedannealinp.d nr

IIII9

5. . (Luke
. . Simulated Annealing Cooling Schedule, 2001).
bttp: //TriRmbers.aol.com/btlukp/siinanft. htm.
6. .
(Metropolis N. Equation of State Calculation by Fast Computing Machines //
Journal of Chem. Phys. 21:1087-1091).
7. . N (NQP) (Schaller N. The N-Queens Problem
(NQP), 2001). bttp: //www.Hsitri.de /projects/NQP/.

.

, ART1,
(Adaptive
Resonance Theory). , . ART1 (
).


(Clustering algorithm) - , () . ,
. , - .
.


,
. , .
, -,
( ).
, ,
, ,
.
.
, , -.
, . ART1 ,

ART1


, .

ART1
ART1 , (Feature vector).
, .
(. 3.1). , ( , 1,
- 0). . 3.1 .

. 3.1. ,
-|
(
). ,
ART1, . ,
( )
.

ARTI
( , )
- (Prototype vector, ( N ). - . -, N, , .
d . (
rho), 0 1,0, - (), *
.
. . 3.1.
3.1. ART1
-
v ( .
-

lilHHIHESI

3.1. ART1 ()

(0 < <= 1)

-

()
-

, . 3.1, .
, -
. . 1, 1. ,
0, 0. , .
- ART1 . 3.2.
3.1-3.4.
-, - - ( 3.1).
-. - ,
-.

- (), ( 3.2), - . , 1, , 1 .
I P , r , E | / ( p + | P J ) > | E | | / + d)

(3.2)

, ,
- ( 3.3).
. , ( ).
.
(< 0,1), -.
|,||/|<

(3-3)

, ,
- ( 3.4). -
. ( )

Ill

ART1 1 1

, -. - ,
- . , .
,-,

(3-4)


- ( . 3.2).

, .
, . ,
,
,
.
^ , . , ,
. , .


. ,
, - P fl ,:
-{1,0,0,1,1,0,1}
, - {1,1,0,0,0,1,0}

:
(3.3)

= {1,1,1,0,0,1,0}
, :

5=7
-1,0
- 0,9

pup .
, , .

ART1, ,
:



,


-

. 3.2. ART 1

V,

,/,

(3.2)
(3.2)
(3.3)
(3.4)

1/5 > 4/8 ()


3/5 > 4/8 ()
3/4 < 0,9 ()
{1,1,0,0,0,1,0} {1,1,1,0,0,1,0) - {1,1,0,0,0,1,0}

- .
3.2, , (0,2 , 0,5). ( . , .

[ ] ! 1
,
, ,. - - ,
( 3.4). -
-:
, . .
ART1
-, .
. ( -
), , .
ART1

ART1 . -, McQueen, , -1
. , ]
( ). ,|
,
. ( ART1) ,
( -) , .
ART
ART1 -|
, . ART1 -]
, ART2
(, ). ARTMAP -
ART, . ART .
;
ART. |
- *
.

ART1
ART1 ;
. , .

ART1

, . , , .
Internet- . , , .
, , .

, , .
,
.
.
( )
, .
Amazon.com ,
.
.
,
.

ART1

ART1 .
ART1 ( ). , ,
( , ),
, (Sum vector). , ART1, (. 3.3).
. , , , ,
. 3.1 ( ).
, () (
0). , 0. , ,

Mil


. (
3.1.

IX)

3.1. ART1
#define MAX_ITEMS
#define MAX_CUSTOMERS
#define TOTAL_PROT0TYPE_VECTORS

(11)
(5)

const float vigilance = 0.9; /* <= < 1 */


int numPrototypeVectors = G;/* -!
int prototypeVector[TOTAL_PROTOTYPE__VECTORS][MAX_ITEMS];
/* */
int sumVector[TOTAL_PROTOTYPE_VECTORSJ EMAXJTEMS];

int members[TOTAL_PROTOTYPE_VECTORSj;
/* , */
int membership[MAX_CUSTOMERS];
. 3.3.

. . ( ) : 66% ( ), , , .
ARTe nanKe/software/ch3
,


ART1 ,
. -,
Linux '
Windows Cygwin.
. -
, .
, 1 , 0 ,

char -itemName[MAX_ITEMS] - {
"Hammer", "Paper", "Snickers", "Screwdriver",
"Pen", "Kit-Kat", "Wrench", "Pencil",
"Heath-Bar", "-Measure, "Binder" };
/*
'
' 1;

*
Hmr Ppr Snk Scr Pen Kkt Wrn Pel Hth Tpm
nt database [MAX_CUSTOMERS] [MAXJTEMS] = {
{ 0,
0,
0,
0,
0,
1,
0,
0,
1,
0,

o,

1,
0,

0,
0,

0,
1,

0,

0,

0,

0,
1,

0,
0,
0.

o.
o.

0,

0,

0,
1.

o,
1,
0,
1,

0,
1,
0 .

o.

0,
0,
1,

0,

0,
1,

0,

0,

0,

0,
0,

0,
0 .

0,
0,
0 .

o.
6,

1,
0,

1,

0,

o,

' o.

1,
0,

0,
0,

0,

0,

0,
0.

o,

1.

0.
1,

1}
0}

0,

1)

1,
0,
0,
0 .

0}
1}
0}
0>


1,

1,

prototypeVector -
. sumVector
ART1. members , membership , . , database .
main ART1,
. main 3.2.
3.2. main ART1

i = 0 ; i < TOTAL_PROTOTYPE_VECTORS ;
(j = 0 ; j < MAX_ITEMS ; j + + ) {
r o t o C y p e V e c t o r [ i ] [ j ] = 0;
u m V e c t o r [ i ] [ j ] = 0;

bersti] - 0;
/*
for (j = 0 ; j < MAX_CUSTOMERS ;
membership[j] = -1;

i n i t i a l i z e 3.3 -,
, members membership.
3.4 - vect rMagnitude vectorBitwiseAnd.
3.4. ART1

srandf time( NULL ) );


initialized ;
performARTl();

i n t j , t o t a l = ,-

displayCustomerDatabas

for (j = 0 ; j < MAX_ITEMS

: (customer = 0 ; cu,

: MAX_CUSTOMERS ;

lakeRecommendation( >

srand -,
i n i t i a l i z e , , ART1, . ART1 performARTl.
makeRecommendation. displayCustomerDatabase - , .
1..
id initialize! void )

(i - 0 ; i < MAX_ITEMS ; i
e s u l t t i ] = [ v [ i ] && w [ i ] ) ;

vectorMagnitude
( 1) . vectorBitwiseAnd ,
.

I S I H U I H I I I
, ,
( ). 3.5.
3.5. -
i n t createNewPrototypeVector( i n t example )

for ( c l u s t e r = 0; c l u s t e r < TOTAL_PROTOTYPE_VECTORS; clusi


if (members[cluster] == 0) b r e a k ;
if ( c l u s t e r = = TOTAL_PROTOTYPE_.VECTORS) a s s e r t ( O ) ;
#ifdef DEBUG

||l

cluster, members[cluster]);
#endif
for (item = 0 ; item < MAXJTEMS ; item++) {
prototypeVector[cluster][item] = 0;
sunivector[cluster][item] = 0;
}
for (customer = 0 ; customer < MAX_CUSTOMERS ; customer++| (
if (membership[customer] == cluster] [
if (first] {
for (item = 0-,- item < MAX_ITEMS ; item++) {
database[customer][item];
sumvector[cluster][item] = database[customer][item];
first = 0,} else {
for (item = 0 ; item < MAX_ITEMS ; item++) {
prototypeVector[cluster][item] =
prototypeVector[cluster][item] &s
database[customer][item];

PrototypeVectors++;
(i = 0 ; i < MAX_ITEMS ;

#ifdef DEBUG
printf("%ld ", exampleji]);
#endif

members[cluster] = 1;
Wifdef DEBUG
printf("\n");
#endif
retu:

clu

, c r e a t e N e w P r o t o t y p e V e c t o r , . - . 1.
u p d a t e P r o t o t y p e V e c t o r s -
, . ( 3.4), - - . 3.5 -,
. sumvector,
ART1.
ART1 3.6. . , #undef #def i n e DEBUG.
3.6. ART1

#ifdef DEBUG
printf("Recomputing pr

i n t performARTl( void )
{
i n t andresult[MAX_ITEMS];

int pvec, magPE, magP, magE;

-
*/
if ((old >= 0) && (old < TOTAL_PROTOTYPE_VECTORS))

int index, done - 0;


int count = 50;

while (Idone) {

updatePrototypeVectors( pvec );

done = 1;
for (index = 0 ,- index < MAX_CUSTOMERS ; index++) {
/* 3 */

} else {
/*

for (pvec = 0 ; pvec < TOTAL_PROTOTYPE_VECTORS ; pvec++) {


if (members[pvec]) (
vectorBitwiseAnd( andresult, ^database[index][0],
&prototypeVector(pvec][0] j;

/* , */
if (membership[index] == -1) {

g P = vectorMagnitude< SprototypeVector[pvec][0] );
magE = vectorMagnitude( Sdatabase[index][03 ) ,-

ma

/* He - 1
*
*/
membership[index] = createNewPrototypeVecto
( &database[index][0] );
done = 0;

result = (float)magPE / (beta + (float)magP);


test = (float)magE / (beta + Ifloat)MAX_ITEMS);
/* 3.2 */
if (result > test) {

} /
nt old;
/* , */
if (membershipUndex] i= pvec) {
-/* */
old = membership[index];
membershipEindex] - pvec;
if (old >= 0) {
members[old]--;
if (members[old] == 0) mimPrototypeVectors-}
members[pvec]++;

if

i :

(! int ) bre,

] /*
return 0;
}

ART1 :
- . , ,
!. 3.1-3.4.
mag* , . , -, ( ).


, . , 3.1.
, makeRecommendation, ( ) - . 3.7.
3.7.

>estltem = - 1 ;
al = 0;
ir (item = 0 ; item < MAX_ITEMS ; item++) {
if ( ( d a t a b a s e [ c u s t o m e r ] [ i t e m ] == 0) &&
(sumvector[membership[customer]][item]
b e s t l t e m = item;

>val])


. ( TOTAL_PROTOTYPE_VEC TORS) ,
. ART1, .
- ART1. ,
, . , ,
. , ,
is , . - ( ) - , - .


r) ;

if (bestltem >= 0) {
printf("The best recommendation is %d (%s)\n
bestltem, itemName[bestltem]);
printf("Owned by %d out of %d members of this
members[membership[customer]]);
[ "No recommendation can be made.\n");

,
, . DEBUG, ART1 .
, , . - ( ) (.
3.8).
, .
3.8.

printf("Already <

s : ">;
m < MAX_ITEMS ; i t e i

printf("\n\n-);
}
. 3.3 }
, .
makeRecommendation ,
( sumVector). :
( )<
, '
( ).

ProtoVector
Customer

Customer
Customer

7
9

ProtoVector

Custoi

0:

0 0 0 0 0 0 0 0 1 0 0
: 0 0 0 0 0 1 0 Q 1 0 0 : G

: 0 0 1 0 0 0 0 0 1 0 0 : 0 :
: 0 0 1 0 0 1 0 0 1 0 0 : 0 :
1

0 0 0 0 1 0 0 1 0 1

: 0 0 0 0 1 0 0 1 0 0 1 : 1
: D 0 0 0 1 0 0 1 0 0 0 : 1 :
1 0 0 1 0 0 0 0 0 0 0
1 0 0 1 0 0 1 0 0 1 0 : 2 :

Hill
Customer 4
Customer 6
ProtoVector
Customer 1
Customer

ProtoVector


: 1 0 0 1 0 0 0 0 0 1 0 : 2 ;
: 1 0 0 1 0 0 0 0 1 0 0 : 2 :
3 : 0 0 0 0 0 0 0 0 0 0 1
: 0 1 0 0 0 0 0 1 0 0 1 : 3 :
= 0 0 0 0 1 0 0 0 0 0 1 : 3 :
4 : 0 0 0 0 0 0 0 0 0 0 0

3.9 , -
.
, .
3.9.
For Customer 0, The best recommendation is 2 (Snickers)
Owned by 2 out of 3 menibers of trixs cluster
Already owns; Kit-Kat Heath Bar
For Customer 1, The best recommendation is 4 (Pen)
Owned by 1 out o 2 members of t h i s cluster
Already owns: Paper Pencil Binder

Owned by 2 out of 3 members of this clusti


Already owns: Screwdriver Wrench Tape-Meai
l be
For Customer 3, No recomnu tatioi
Already owns: Pen P e n c i l :
ART1 rpyi
, . 0 1*
, 1 - ,;
2 - . ,
. ,
3 . ,
, - ( .]
, ,
.


-
. 6rij
. . npjj
, >.

(, 100-103).
. ART1 , , .
,
erne .
, . , ,
. ART1 .
, .
. , ,
.
, ,
. , ,
. , , , .


ART1 (). () . , ,
. :

;
;
;
;
Internet;
(data mining).

, .
, . Internet .

, , . Internet -;
Web-, ,
. , -1
. - ]
ART1 , - '<
Internet.

, j
.
j


1. Wolfram Research. (Eric Weisstein'si
World of Mathematics). http://mathwor1d.wolfram .r,om /.;
2. . (Gallant S. Neural Network Learning. - {
Cambridge, Mass.: MIT Press, 1994).
j
3. ., . --.
, (Carpenter G.,:
Grossberg S. A Massively Parallel Architecture for a Self-Organizing N e u r a l
Pattern Recognition Machine // Computer Vision, Graphics and Image)
Processing, 37: 54-115, 1987).
\

4.
,
, . (Ant algorithms), ( ,
(Marco Dorigo)), , , .
(
, ,
). ,
,
, , .


, , . ,
, , .
- ,
. ,
. , . , , .
,
. *- .
,
, . . , . ,
.

||

j||

, . 4.1. , . , .

( J

. 4.2. (,)

. 4.1. (TJ
. -]
, - .
, -1
(. 4.2).
, -ij
. -]
, (. 4.3).
, ^
. 0 - 2
. ,
4 , t
. ]
, . , .

- -


, ,
.

, . , - , . , , . ,
(. ).

EZUHHMIL

1111

- , - . , . (tabu list), , .
, .
, , (Hamiltonian path), (Sir William Hamilton).
- , . .

. . , , .


.
,
.
, ,
, .


. 4.3. (


. (path),
, 4.1:
= -

r(r,uT x

(4.1)

(,) - , (,) , , a , - . , . , ,
( ). , . , .
V - f 1,2,3,4}
. 4.4. Vc


, . , ,
. -

E O H M H I I I I

, . 4.2 , . Q .

_-

(4.2)

Lk(t)

, - , -
. 4.3, .

, ,
.
,
, . - 0 I.


.
, ,
(Pheromoiie evaporation).
4.3, 4.4.
z.^t) - .) (\-)

(4.4)


, ,
. , . -'
, 4.1

,
. , .


, , . (. 4.1) , . . 4.5
(Vo Vj).
, .

. 4.5.
,. ,
. . 4.6 (
, , - ).
. 4.6 , \ 20 , , 10. 4.2 , .
, (, , ),
. .
4.3 ,
. \ :
- 0,1 + (0,5 0,6) - 0,4.


, ( 0,28), :
(0,28) 3 0 (1,0)* / ((06) 3 0 (0,5) 1 ) + ((0,28) i 0 (1,0) 1 ) - 0,021952 / 0,024 - (0,915).
, .

= 0,6
= 3,0

20

10

Q/

0,5

1,0

(Traveling Salesman Problem - TSP). , ,


, . , , - . TSP
1930- ., , (Karl Menger) .
, 19 .
(Sir William Rowan Hamilton).
, TSP, .

./software/ch4,

. 4.6.

, :
= 0,1 + (1,0x0,6) = 0,7.
4.4 , , , . ( ) :
- 0,4 (1,0 - 0 , 6 ) = 0,16
- 0,7 (1,0 - 0 , 6 ) = 0,28.

, .
, (),
. 4.1 , .
4.1.


( , ).
4.1, , .
, ( 0,16), :

define MAX_CITIES
3D
define MAX_DISTANCE 100

(0,16) (0,5)' / <(0,16)


= (0,085).

int y,} cityType,-

((0,28)

> - 0,002048 / 0,024 -

#define MAXJTOUR
typedef struct {

(MAX_CITIES * MAX_DISTANCE)

HJ
#define MAX_ANTS

30

ed char tabu[MAX_CITiES];

cityType cities[MAX_CITIES];

i tyType MAX_DI STANCE HaMAX_DiSTANCE. antType .


( c u r C i t y nextC i t y ) , !
( t a b u ) . ,
t o u r L e n g t h .
TSP
. !
TSP 30 ( 4.2).
.
,
4.2. ,

ffdefi
ALPHA
ffdefine BETA

1.0
5.0

#defi ne RHO
#defi ne QVAL

0.5
100

# d e f i n e MAX_TOURS

20

MAX_TIME

c i t i e s a n t s .
, d i s t a n c e , .
pheromone. , , . 4.3,
- 4.4.
4.3.

double tourLength;
} antType;

define

antType ants[MAX_ANTS];

double pheromoneEMAX_CITTES][MAX_CITIES];
double
int

best=(double)MAX_TOUR;
bestlndex,-

i n i t (. 4.4).
4.4.

void init( void )


{
*/
for

(MAXJTOURS * MAX_CITIES>

# d e f i n e INIT_PHEROMONE

(1.0

/ MAX_CITIES)

ALPHA () (
). )
( ). RH0 ()
, ( !
), ( 1 . 0-)
. QVAL ( (
4.2) - , , *
. )
.

: MAX__CITIES ,
'* */
: i t i e s [ f r o m ] . x = getRanclf MAX_DISTANCE );
: i t i e s [ f r o m ] . = getRandl MAX_DISTANCE );
:or [to = 0 ; to < MAX_CITIES ; to++) {
distance[from][to] = 0.0;
pheromonelfrom][to] = INIT_PHEROMONE;

*/
MAX_CITIE3 ; from+-

1 | |
if ((to != from) && (distance[from][to] == 0.0)) {
int xd = abs(cities[from].x - cities[to].x);
int yd = abs(cities[from].y - cities[to].y];
distance[from][to] = sqrt ( (xd * xd) + (yd * yd) );

nt = 0 ; ant < MAX_ANTS ; ant+


, a n t . ,
. to
. to , ( 0),
. c u r c i t y a n t ( ). t a b u
p a t h . t a b u , ;
, . p a t h
, t o u r L e n g t h ( ).
, . r e s t a r t Ant s ( 4.5).
4.5. restartmts


ant, i, to=0;
)r ( from = 0 ; from < MAX_CITIES ;
ants[ant].tabu[from] = 0;
ants [ant] .path[from] - -1,ants[ant].pathlndex
ants[ant].tourLength = 0.0;
- ,

0 ; ant <; MAX_ANTS ; ant++ ) {


.f (ants[ant].tourLength < best) {
best = ants[ant].tourLength;
bestlndex = ant;

ants[ant].tourLength = 0.0;
for (i = 0 ; i < MAX_CITIES ;
a n t s [ a n t ] . t a b u l i ] = 0;
ants[ant].path[i] = - 1 ;

if

i n i t ,
. - .
, ( MAX_Cll
TIES) ,
. , <
d i s t a n c e p h e r o m o n e .
, ,
, .
( ).

(to

==

MAX_CITIES)

to

ants[ant].curCity = to++
ants[ant].pathlndex = 1;

ants[ant].tabu[ants[ant].curCity] = 1;

, .
- .

||

s e l e c t N e x t C i t y
. a n t P r o d u c t , -1
4.1 (. 4.6). pow (
.
4.6. antProduct selecCNextCi
double antProduct( i n t from, i n t to )
{
r e t u r n (< pow< pheromone[from][to], ALPHA ) *
pow( (1.0 / d i s t a n c e [ f r o m ] [ t o ] ) , BETA ] ) ) ;

s e l e c t N e x t C i t y ,
tabu. 4.1, . s e l e c t N e x t C i t y
. ,
, 4.1, . , , .
, s i m u l a t e A n t s ,
( 4.7).
4.7. siulateAnts

double denom=0.0;
/* */
from = a n t s [ a n t ] . c u r C i t y ;

i n t simulateAnts( void )
{
i n t k;
for (k = 0 ; k < MAX_ANTS ; k+ + ) {
/* , */
if (ants[k].pathlndex < MAX_CITIES) {

r (to = 0 ; to < MAX_CITIES ; to++) {


if ( a n t s [ a n t ] . t a b u [ t o ] == 0) {
denom += antProduct( from, to );

a n t s [ k ] . t a b u [ a n t s [ k ] . n e x t C i t y j = 1;

do {

ants[k].tourLength +=

double p;
/* (
* )
*/
if (ants[k].pathlndex == MAX_CITIES) {
ants[k].tourLength +=
distance[ants[k].path[MAX_ClTlES-l]][ants[k].path[0]];
)

if (to >= MAX_CITIES) to = 0;


if ( a n t s [ a n t ] . t a b u [ t o ] == 0 ) {
p = antProduct(from, to)/denom;
1

if (getSRandf) < p ) break;

} while (1);

antsEk].curCity = a n t s [ k ] . n e x t C i t y ;

s i m u l a t e A n t s a n t
, 4.1.
p a t h l n d e x , ,
. s e l e c t N e x t C i t y ,
. a n t ]
n e x t c i t y , p a t h t a b u . t o u r L e n g t h |
. , ,
t o u r L e n g t h .
.
s i m u l a t e A n t s '
. s i m u l a t e A n t s ,
, - , .
.
, !
, . u p d a t e ^
T r a i l s ( 4.8).

if (i < MAX_CIT:

pheromone[to][from] - pheromone[from][to];

for (from = 0 ; from < MAX_CITIES ; from++) {


for (to = 0 ; to < MAX_CITIES ; to++) {
pheromone[from][to] * = RHO;

4.8. updateTrails - j
void updateTrails( void )

; */
>r ( f n i = 0 ; from < MAX_CITIES ,
or (to = 0 ; to < MAX_CITIES ; to++) {
if (from '= to)

pheromone[from][to] *= (1.0 - RHO);


if (pheromoneffrom][to] < 0.0)
pheromone[from][to] = INIT_PHEROMONE;

u p d a t e T r a i l s , *
, .
4.4. -
, . a n t ,
p a t h ,
4.2. RHO, , .
m a i n (. 4.9).
,
_1. ( s i m u l a t e A n t s ) , u p d a t e T r a i l s , .
4.9, m in
int main()

/* */
for (ant = 0 ; ant < MAX_ANTS ;
ir (i = 0 ; i < MAX_CITIES ;

\\

le (curTime++ < MAXJTIME) {


f ( simulateAnts() ==' 0 ] {
updateTrailsO ;
if (curTime !=' MAX_TIME)
restartAnts0;
%d (%g)\n", curTime, best);

}||||


90

70
60
1

50
printf("best tour %g\n", best);
printf< n \n\n"|;
emitDataFile( bestlndex );

40
30
20
10

, *|
r e s t a r t Ant s. , -|
. r e s t a r t A n t s
, . , -j
, , '
.
/

-+

+_,--+\

J
--4
10

20

30

40

50

60

70

80

90 100

. 4.7. 30

emitDataFile,
,
.
7emmi.dmk.ru.


;
.
30 (. <
: = 1,0, = 5,0, = 0,5, Q = 100.
50 (. 4.8
, .
,
.
.

10

20

30

40

50

60

70

80

90

. 4.8. TSP 50

100

J H H H E O



( )
:
(The Ant System: Optimization by a Colony of Cooperating Agents)|

.

Alpha (a) / Beta )


/\ !
. . 4.1.
4.1. /

\fi

5.0

( 4.1),
- ( ). ,
,
. , .
.

Rho(p)
, *
, (1,0 - ) '
. > 0,5, ~
. < 0,5
.
, '
.

.
, .
,
.


,
.
(Quadratic Asigment Problem QAP) m
( ). , , , . .
(Job-shop Sheduling
Problem - JSP). J ( , ) , .
, , ,
, .
, , , . *.
(Ant Algorithms for Discrete Optimization).

, . , (
). (TSP). , ,
.


1. Wolfram Research. (Hamiltonian Path). http://mathworld.wolfrani.com/HamiltoriianPath.htniL
2. . Web-
, http://iridiaulb.ac.be/-mdorigo/ACO/ACO.html.
3. . {Dorigo M.
Ant Algorithms for Discrete Optimization, 1999). http://
citeseer.nj.nec(-on/420280.html.

4 .
(Dorigo M. Ant Colonies for the Travelling Salesman Problem // Biosystems,
43:73-81, 1996).
5. . : (Dorigo M. The Ant System: Optimization by a Colony of
Cooperating Agents / / I E E E Transactions on Systems, Man and Cybernetics. Part B26, (1):1-13, 1996).
6. . (Applegate D. History of the Traveling Salesman Problem, 2003).
http-/wwwmath.nrincrtnnedu/tso/histmain.html.

:!

5.


, . ,
, , , .
.
,
, .
, ,
.
.
, ^ .


(Neural network) . , . : , , ,
. 1 0 . 1000 (
,
). , (. 5.1).
: , ( ) , !-
() .
. , .

1||'

, 5.1, , , . ,
, 5.2 ( ).
= -1,(<0)

(5.2)

= 1,(>0)

,
- 1 .

. 5.1.

1.

SLP


(Single layer perception - SLP)
, . -1
, ,|
w., . . , - -|
. . Cxt
. 5.2.
. 5.2 (,, 2 3 ). , -J
(w 0 ), .
(w,, w2 w 3 ). , , . -J
5.1.

, . , , . 5.3.

(5-1)1
. 5.3. ,

, 1, I, 0.
( = (1,1)), , 5.2 - , :
= + u i w i + u2w2

1 - (-1 + (1 1) + (1 1)).
= (0,1):
= + u,w, + u^

1 - (-1 + (0 1) + (1 1)).
. 5.2.

, ( ).

111

, -1
(XOR). XOR !
. - 1960- . 1
!
.
-1
(. . 5.4). -
, (Multiple^
layer perceptron - MLP).

;;|||
()


, CBJ
. . 5.4 )
, ( ) ]!
()
. ;
un. (,, 2 ), (u 3 , u 4 ),
- ( 5 ). '
w, i^ u r

. 5.5. ,

. 5.4.
(, 2 )
, ( 5.1
!
( ), . |
. 5.5.
. . 5.6
, . 5.4. 5 :
( 3 ^) w 5 3 w5
, ^
. 5.6, ,

. 5.6.
. . 5.6
.
f(x) , .

|||

^ ^ " ^ ^ ^ ^ ^ ^ ^


, .



(Backpropagation algorithm) - . , , ,
. , .

, - ( ).
,
. ,
. , . , ,
.
.

, , . 5.7.



. , ,
, :
1. .
2. ( S, ).
3. , ,
( 5.3 5.4):
5 U = ( ; - u 5 )u 5 (l - u 5 )
^

(^>i

n ,j 5 0 )u.(l - .)

(5.3)
(5.4)

( , m , !
,
, - ).
, w -
f

( 5.5 5.6):]
4. ,

- + p50u;

(5.5)|
(.

( ).
, niareJ
' , 4,

.
(0,1) .

. 5.7.

. ]
:
u 3 = f(w 3 1 u, + w 3 ; u 2 + w b x )
u 3 = f ( l x0 + 0,5'xl + lx l) = f(l,5)
u 3 = 0,81757;

,*-(so><w5*>ku<*(1.o-u<)
6,4 - (0,0373 -1,0) 0,952574 (1,0 - 0,952574)
6 - -0,0016851;
s

,,s " (5. * SJ > * " * < ' ' - j>


S113 - (0,0373 1,5) 0,81757 (1,0 - 0,81757)
5 - 0,0083449.

u4 = f(w4 ,u, + w4^u2 + wb x )


u 4 - f ( - i x 0 + 2 x 1 + 1 x 1) - f(3)
u 4 - 0,952574.

, f(x) , ( 5.7):
f(x) - l/(l+e-)
. , . v

:
. = f(w 5 ^u 3 + w 5 4 u 4 + wb x )
u 5 = f(l,5 x 0,81757 + -1,0 x 0,952574 + l x l ) = f(l,2195)
u 5 = 0,78139.

, ,
5.3 5.4 .
(), 0,5.
:
w

* u " w y + P5oui
w M - w M + (p x 0,0373 x u,)
w51 - -1 + (0,5 x 0,0373 x 0,952574)
w s 4 - -0,9882;
w u - w s , + (p x 0,0373'x u,)
w J S - 1,5 + (0,5 x 0,0373 x 0,81757)
wa1,51525.


1,0; , , 0,78139. ,
,
.
^ ~
. 5.8

:
err - 0,5 (1,0 - 0,78139) - 0,023895.

,
. 5.1,
:
50 - (1,0 - 0,78139) 0,78139 (1,0 - 0,78139)
50 - 0,0373.
. .
( 5.5), BI
5.9:
(1,0 - )

5.2, :

(5.9

:
w
sb - w i b + ( * . 0 3 7 3 * ,)
w s b - l 4-(0,5x0,0373x1)
w s b - 1,01865.

w 5 i , w M - . .
.
( ):

" wu + (P * -0,0016851 x u,)


- 2 + (0,5 x -0,0016851 x 1)
- 1,99916;
- w 4 , + (p x -0,0016851 x ,)
- -1 + (0,5 x -0,0016851 x 0)
--l,0;
" W 32 + <P x 0,0083449 x n 2 )
- 0,5 + (0,5 x 0,0083449 x 1)
-0,50417;
" w si + <P * 0,0083449 x u,)
- 1,0 + (0,5 x 0,0083449 x 1)
- 1,0.

^
- :
w l b = w 4 b + ( -0,0016851 ^)
w i b - 1,0 + (0,5 -0,0016851 1)
w^-0,99915;
w 3 b =* w 3 b + (p x 0,0083449 x 3)
w 3 b - 1,0 + (0,5 x 0T0083449 x 1)
w a b - 1,00417.
. , , :

.
,
.
,
.
. 5.8, , . *
.
,
. ,
, .

u3 = f(w31u1 + w3 2u2 + wb x )
u 3 = f(l x 0 + 0,50417 x 1 + 1417 x 1) - f(l,50834)
u =0,8188;
^ 2 u 2 +'wb x )
u
( u, +
u 4 = f(-l x 0 + ^
^99916 x 1 + 0,99915
5 x 1) - f(2,99831)
u 4 = 0,952497;
u 5 = f(w 53 u3 + w g i u 4 + w b x )
u 5 = f(l,51525 x 0T81888 + -0,9822 x 0,952497 + 1,01865 x 1) - f(lT32379)
u s - 0,7898;
err = 0T5 x (1,0 - 0J898) 2 = 0,022.
, 0,023895. :
0,022, ,
0,001895.


1^
. (Neurocontroller]
, . ]
, ]
, .
.
, , . <
(
), . -)
, -|
, .
, ,

. 5.8,


. - |
- , |
. - |
, (. 5.9).

^^ W^
, , ,
. , .
, .
. 5.10 , . (0 - , 2 - ), (1, , 0 ), ( 1 , , 0 ) ( ).
, . , ,

. 5.9.
, , )
i
.
, . ;

. 5.10.

x
, - 1
, . - |
, , - j
.
( )
. 1
100%
-1
, -1
.



. J
.
!
. -

. , , -
, - . , ,
, .

5.1. ,
()

, . 5.1, .
. 5.11.
.



. , ,
, .
, ;
. ,
. 5.1.
5.1. ,

. 5.11.

IIIL

Jj

. . .
. ,
.
, - j
. , ,
. ,
, f
.
, - |
, ( 2:1:1:1), . - 1
. , , 1
( 2:1:0:3). "!
, . -1
. 5.2.
5.2. ,

(2)

(1)

(0)
(0)
(2)
(2)
(0)

,
(. 5.2). ]
, .


* 1


!:
, ,
. - 1
5.1.

5.1.

#define INPUT_NEURONS
#define HIDDEN_NEURONS
#define OUTPUT_NEURONS
/*

4
3
4

*/

double wih[INPUT_NEURONS+l][HIDDEW_NEURONS];
/* ( ) */
double who[HIDDEN_NEURONS+l][OUTPUT_NEURONS];
/ */
double inputs[INPUT_NEURONS];
double hidden[HIDPEN_NEURONSj;
double target tOUTPUT_NEUBONSJ,double actual[OUTPUTLNEUKONSJ;
/* */
double erro[OUTPUT_NEURONS];
double errll[HIDDEN_JJEUROHS] ;
(wih),
(who). 5 (
(. 5.10) , w i h [ 0 ] [0]
( , - , a u s - ,
). w s | . w | l T (.
] | 7 )[2] [ 3 ] . +1 wih who.
. i n p u t s
, hi dden , t a r g e t , a c t u a l .
.
. e r r h .
,
, 5.2.
5.2.

#defi] i LEARN_RATE
#defii i RAND_WEIGHT

0.2
/
( (Cflc

(float)RAND_MAX)

*/

>at)RAND__MAX)

0.5)

^^^|1

ttdefine s q r ( x )

((x)

^1 _]||
5.4.

) ( i n t ) ((x) * getSRandO )
(x))

( -0,5 0,5). -|
0,2.
.
, , ;
, . <
5.3.
5.3.
v o i d assignRandomWeights( void )
{
i n t hid, inp, out;

void feedForward( )
{
i n t inp, hid, out;
double sum;

/* */
for (hid = 0 ; hid < HIDDEN_NEURONS ; hid++) {

= 0 ; inp < INPUT_NEURONS ; inp++)


inputs[inp] * wih[inp][hid];

/ * * /
sum += wih(INPUT_HEURONS][hid];

for (inp = 0 ; inp < INPUT_JIEURONS+1 ; inp++) {


for (hid - 0 ; h i d < HIDDEN_NEURONS ; hid++) f
w i h [ i n p ] [ h i d ] = RAND_WEIGHT;

/*
for (hid = 0 ; h i d < HIDDEN_NEURONS+1 ; hid++)
for (out = 0 ; out < OUTPUT_NEURONS ; Out++)
whoEhid] [out] = RAND__WEIGHT;

{
{

t */
< OUTPUT_MEURONS ;

i = 0.0;
(hid = 0 ,- h i d < H DDEIOJEURONS ; hid++)
sum += h i d d e n [ h i d ]

double sigmoid( double v a l )


{
r e t u r n (1.0 / (1.0 + e x p ( - v a l ) ) ) ;
)

who[hid][out3;

/ * * /
sum += who[HIDDEN_NEURONS][out];
a c t u a l f o u t ] = sigmoid( sui

double sigmoidDerivative( double val )


{
return ( val * (1.0 - val) );
}
assignRandoraWeights
( ). sigmoid !
(),
( 5.5). sigmoidDerivative
sigmoid !
.
()
5.4).

5.4,

. .
. ,
. ,
.
5.5.

IlEi

E ^ J ^!11!5 "^"p

5.5.

, -
-. (
) . . ,
, .
, , . .

. , .
5.6 ,
. (, , , ),
( o u t ) . 5.6 .

void backPropagate( void )


i n t inp,

hid,

out;

/* ( 3 J
for (out = 0 ; out < OUTPUT_jffiURONS-; out++) {
erro[out] = (target[out]-actual l o u t ] ) *
sigmoidDerivative( a c t u a l [ o u t ] ) ;
/* { 3.
for (hid = 0 ; hid < HIDDEN_NEURONS ; hid++) {
errh[hid] = 0.0;
for (out = 0 ; put < ODTPUT_NEURONS ; out++) {
errMhid] += erro[out] * who[hid] [out] ;
}

5.6.

errhfhid] *= sigmoidDerivative{ hidden[hid] );

/* { 4 ) */
for (out = 0 ; out < OUTPUT_NEURONS ; out++) {
for (hid = 0 ; h i d < H1DDEN_NEURONS ; hid++) {
whofhid][out] += (LEARN_RATE * e r r o [ o u t ] * h i d d e n [ h i d ] J ;

typede E struct {
doub e health;
doub e knife;
doub e gun;
doub e enemy;
doub e out[OUTPUT_NEURONS]
} ELEMENT;
#define MAXSAMPLES 18

/*
who[HIDDEN,NEURONS][out] += (LEARN_RATE * e r r o [ o u C ] } ;
/* { 4 ) */
for (hid = 0 ; hid < HIDDEN_NEURONS ; hid++) {
for (inp = 0 ,- inp < INPUT_NEURONS ; inp++) {
w i h l i n p ] f h i d ] += (LEARN_RATE * errhChid] - i n p u t s [ i n p ] ) ;
/* */
wih[INPUT_NEURONS][hid] += (LEARN_RATE * e r r h [ h i d ] ) ;

ELEMENT
{ 2.0,
{ 2.0,
{ 2.0,
{ 2.0,
{ 2.0,
{ 2.0,

samples[MAX_SAMPLES]
0-0, 0 . 0 ,
{0.0,
0-0, 0 . 0 , .0, {0.0,
0 . 0 , 1.0, .0, {1.0,
0 . 0 , 1.0, .0, {1.0,
1.0, 0.0, .0, {0.0,
1.0, 0.0, . 0 , 11.0,
0.0,
0.0,
0.0,
0.0,
1.0,
1.0,

0.0,
0.0,
1.0,
1.0,
0.0,
0.0,

{ 0.0, 0.0, 0.0,


{ 0.0, 0.0, 0.0,

.0,
.0,
.0,
.0,
.0,
.0,

{0.0,
{0.0,
{1.0,
{0.0,
{0.0,
{0.0,

. 0 , {0.0,
. 0 , {0.0,

i
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,

1.0,
1.0,
0.0,
0.0,
0.0,
0.0,

0.0}
0.0}
0.0}
0:0}
1.0}
0.0}

},
},
},
},
},
},

0.0,
0.0,
0.0,
0.0,
0.0,
0.0,

1.0,
0.0,
0.0,
0.0,
0.0,
0.0,

0.0}
1.0)
0.0}
1.0}
1.0}
1.0}

},
},
},
},
},
},

0.0, 1.0, 0.0}


0.0, 0.0, 1.0}

},
},

&
{
{
{
{

0.0,
0.0,
0.0,
0.0,

0.0,
0.0,
1.0,
1.0,

1.0,
1.0,
0.0,
0.0,

1.0,
2.0,
2.0,
1.0,

{0.0,
(0.0,
{0.0,
{0.0,

0.0,
1.0,
1.0,
0.0,

0.0,
0.0,
0.0,
0.0,

1.0}
0.0}
0.0}
1.0}

},
},
},
}

, (2 - , 1 -
0 - ). < !
(1 - , 0 - ),
. ,
.
*-,
,
. )
, ( 5.7). F

s t r i n g s , .
5.7. "
char * s t r i n g s [ 4 ] = t " A t t a c k " , 'Run-, "Wander", "Hide"};

/* */
srand{ time (NULL) ),assignRandomWeights();
/* */
while (1) {
if (++sample == MAX^SAMPLES) sample = 0;
inputs[0] = samples[sample].health;
inputs[1] = samples[sample].knife;
sample].gun;
sample].enemy;
sample].out[0];
target[l] = samples[sample].out[1];
target[2] = samples[sample].out[2];
target[3] = samples[sample].out[3];

i n t index, s e l ;
double max;

feedForward();

s e l = 0;
max = vectorlsel];

err = 0.0;
for (i = 0 ; i < OUTPUT_NEURONS ; i++) {
err += sqr( (samples[sample].out[i] - actualfi]) );

for (index = 1 ; index < OUTPUT_NEUROKS ; index++) {


if (vector[index] > max) {
max = vector[index]; sel = index;

.00000) break;
, 5.8 main,
.
5.8. main,

int main{)
{
double e r r ;

backPropagate{);

/* */
or (i = 0 ; i < MAX_SAMPLES ;
inputs[0] = sampleslij.health;
inputsU] = samples[i] .knife;

j|
inputs[2]
inputs[31
target[0]
target; [1]
target[2]
target[3]

= samples
= samples
= samples
= samples
= samples
= samples

inputsfO] = 2.0; inputs[l] = 1.0; inputs'[2] = 0.0; inputs[3] = 3.0;


feedForwardO ;
printf("2103 Action %s\n", strings [action(actual) ]),-

il-gun;
i].enemy;
i].out[0];
i].out[l];
i}.out[2] f
i].outI3]f

inputs[0] = 0.0; inputs[1] = 1.0; inputs[2] = 0.0; inputs[33 = 3.0;


feedForward();

feedForwa rd 0 ;
if

fclose(out);

(actio
f("%2.1g:%2.1g:%2.1g:%2.1g %s (%s)\nn,
inputs[01, inputs[II, inputs[2], inputs[3],
strings[action(actual)], strings[action(carg

) else {
)

printf("Network is %g%% correct\n",


{ ( f l o a t ) s u m / (loat)MAX_SAMPLES) * 1 0 0 . 0 ) ;

/* */
/*

*/
inputs[0] = 2.0; inputs[1] = 1.0; inputs[2] = 1.0; mputs{3]
feedForwardO ;
printf(-2111 Action %s\n", strings[action(actual)]);
inputsfOl =1.0; inputs [I] = 1.0; inputs[23 = 1.0; inputs[3J - 2.0;

P r l S r i S ' L t i o n %e\-. stringstactionUctual,],;


inputs[0] - 0,0; inputs[l] * 0.0; inputs[2j = 0.0; inputs[3] - 0.0;
feedForwardO ;
nrintff"0000 Action %s\n", strings[action(actualJ J);
inputs[0] = 0,0; inputs[l] - 1.0; inputs[2] = 1-0; inputs[31 - 1.0;
feedForward();
p r i n t f C O l l l Action %s\n", stringstaction(actual)]);
inputs[G] = 2.0; inputs[l] = 0.0,- inputs[23 - 1.0; inputs[3] = 3.0;
feedForwardO;
printf(-2013 Action %s\n", strings[action(actual)3);

s r a n d
.
w h i l e . ,
.
, - . ,
, . ,
, . ,
.
,
.
, ,
.


, .
, . .
, .
, , ,
. .
- , , , . , .

[I3HHBeiIlf^J^ B e e^!1?AE^y T ?J^py __



.
( !
). , ~
. ~
, -1
, ,
.
. , . :
,
. , .


:
, . !
:
Q ;
;
;
;
D ;
;
.


.
. ,
. - :
^
,
, *
.


1. ., . - (1744-1829) (Waggoner Speer
. Jean-Baptiste Lamarck (1744-1829)). h t t p : / /
wwncmn.berkelfv fa/history/lamairbhtmh
2. . (Gallant S.
L, Neutral Network Learning and Expert Systems. - Cambridge Mass MIT
Press, 1994).
"
3. ., . :
(Minsky ., Papert S. Perceptrons: An Introduction to Computational
Geometry. - Cambridge, Mass.: MIT Press, 1969).

*^

6.


. ,
(John Holland), ,
.
,
, .|
(John Koza) .


(Genetic algorithm)
, (
). ,
,
. , ,
, . , noi
. .

( ) ,
, .
.
(

). . 6.2.

(
).
.
. , ,
.
. , . .

. 6.2.

(Initialization) . , * (. 6.3).


^
, , .

<

(.
6.1).
,
(. 6.1),

-^j
L_,
,
^""^
. ;
^__^__^
,
1

*
1 -^
.
. 6.1.
-1

|

(to)

'

. 6.3.

lJtHt?^Xll!i^5J!^^_^l!^P^T?1^'

,
. \
, , 1

'..

(Evaluation) ,
() .

. *
(. 6.4).

{to)

4
5

. 6.4.

(Selection) , ,
. -j
.
( , -
). ,
, . i
, , -1
. , -
( ). - f
. 6.5.
. . 6.5 , - 1
, . -1
. |
, , )\

1(7%)

>

5(38%)

4 (32%)

1(7%)

2(16%)

(to)

. 6.5.
( ) . , . . 6.5
2 , 3 -, 5 - . 1 4 , .

(Recombination) , , ,
.
, - . . , .
.
. 6.6.

Ci

(to)


(t,)

. 6.6.

. , - 1
(- 3
, ).


(Genetic operator), I
. j
, , .

(Crossover) , ( ),
. .
( ) (. 6.7). (. 6.76).
,
.
.
. , , .

. 6.7.

. 6.76.

(Mutation) ( ). . ,
-
(. 6.8).

. 6.8.
,


6.2.

. -
, .
, 6.1:

0
,

/(,)=-

c,(J
. 6.10.
6.1,
z-

6.1. (
X

-1.,

-2

1,5

0,5

-1

'

, , . ,
. 6.1 . ,
. . 6.2 .

0,167

-2

1,5

0,31

-1

0,44

0,007

0,5

0,8

1,5

-1

0,24

0,5

0.19

-1

-1

0,33

, . 6.2, . 6.3. , ( ^ 0,44, t, 0,8). , ,


. 0,231, 0,39, .
. ,
(, ,
, 0,1).

( ),
. ,
. . 6.1 ,
.

0,5

-1

, , .
. . 3 2
, 3 - .
, , . . 6.3
( ), .
6.3. ( tt)

. 6.9 ( ) |
. 6.10 ( ).

. 6.9.
6.1

, ,
. , , .


, !
.
, !
(]
).

-1
( ). , |
, . -1
, . 6.4. |
6.4.

,
, END.
,
, , ( ).
'

,
.
, . ( , ).

& . , * mww.dmk.iu.


, , . .


. I
, , _- |
(, - |
):

,
(X X, ).


, , ( - '
). - :
, . ( DUP = 0 NOP = 5).
, .



, . ,

(Virtual machine - VM) ,


, . 6.1 VM (
common.h s t m . c ) .
6.1.
#define
#define
#define
Sdefine
Sdefine
Sdefine

DUP
SWAP
MUL
ADD
OVER
NOP

0x00
0x01
0x02
0x03
0x04
0x05

#define MAX_INSTRUCTION
define NOME
#define STACK-VIOLATION
Sdefine MATH VIOLATION
#define STACK_DEPTH
i n t stack[STACK_DEPTH];
int stackPointer;

Ill _jBEte

#define ASSERT_STACK_ELEMENTS(x)
if (stackPointer < x) { error = STACK_VIOLATION ; break; }
#define ASSERT_STACK_NOT_FULL \
if (stackPointer == STACK_DEPTH) {
break; }

= STACK_VIOLATI0N

#define SPUSH(x) (stack[stackPointer++] =


#define SPOP
(stack[==stackPointer])

: (]
' progLength -
[
args -
' argsLength -
int interpretSTM(const int program, int progLength,
const int *args, int argsLength]
{
int pc = 0,i n t i, error = HONE;
int a, b;

/* */
for {i = argsLength-1 ; i >= 0 ; i} {
SPUSH(args[i]);
*/
== NONE) &b (pc < progLength)) {

itch(program[pc++]} {
case :
ASSERT_STACK_ELEMENTS(1);
ASSERT__STACK_NOT_FULL;
SPUSH(SPEEK);
break;
case

:ase MUL:
ASSERT_STACK_ELEMENTS(2};
a = SPOP; b = SPOP;
SPUSH(a * b);
break;
:ase ADD:
ASSERT_STACK_ELEMENTS(2);
a = SPOP; b = SPOP;
SPUSH(a + b ) ;

.nterpretSTM

/*
while ((err

stack[stackPointer-2] = a;
break;

SWAP:

ASSERT_STACK_ELEMENTS(2) ;
a = stack[stackPointer-l];
stack[stackPointer-1] = sta

case OVER:
ASSERT_STftCK_ELEMENTS(2);
SPUSH(stack[stackPointer-2]);
break;
} /* s w i t c h */
} /* */

6.1 ,
. , , ( , NONE, , ).
, ( s t a c k ) , VM. ASSERT_XXX (, , ). SPEEK, SPUSH SPOP
.
i n t e r p r e t STM .
( p r o g r a m ) ( p r o g L e n g t h ) ,
( a r g s ) ( a r g s L e n g t h ) . VM .
,
, , .
, ,
.
,
.

/* */
performFitnessCheckl fp );


^
, !
(. 6.2). -1
- main, , , JT
.

/* ( 100 ) */
if ((generation** % 100) == 0) {
printf("Generation %d\n", generation-1);
n
printf( \tmaxFitness = %f (%g)\n", raaxFitness, MAX_FIT);

main
main, 6.2, !
.

= %d\n", curMutations);

6.2. main -
{
int generation = 0, i;
FILE *fp;
extern float minFitness, maxFitness, avgFitness;
extern int curCrossovers, curMutations;
extern int
curPop;

' . .

: ( generation > (MAX_GENERATIONS * 0.25) ) {
if ((avgFitness / maxFiCness) > 0.98) t
printf{"converged\n');
break;

void printProgram( int, int );


/* */
srand(time(NULL}) ,-

if

if (maxFitness == MAX_FIT) {
printf{"found solution\n");
break;

(fp == NULL} e x i t ( - l ) ;

/* i !
*
*/
initPopulationO ;
performFitnessCheck( fp );
/*
while (generation < MAX_GENERATIONS) {
curCrossovers = curMutations = 0;
/* 2- , ,
performSelectionO ;
/ */
curPop = {curPop = = 0 ) ? 1 :

, 2-

/* */
printf(\tavgFitness
printf ("\tminFitness
printf("\tCrossovers
printfC\tMutation

=
=
=
=

%f\n-, avgFitness);
%f\n", minFitness) ,%d\n", curCrossovers);
%d\n", curMutations);

/* */
for (i = 0 ; i < MAX_CHROMS ; i++) {
if (populationsIcurPop][i].fitness == maxFitn
int index;

(index = 0 ; inde < populations[curPop][i].progSize ;


index++)
{
index
printf("%02d ", populations[curPop][i],program[index]);
}
printf("\n">;
p r i n t f ( - F i t n e s s %f\n", p o p u l a t i o n s [ c u r P o p ] [ i ] . f i t n e s s ) ;
p r i n t f ( " P r o g S i z e %d\n\n", p o p u l a t i o n s [ c u r P o p ] [ i ] . p r o g S i z e ) ;
p r i n t P r o g r a m ( i , curPop);

c u r P o p , ;
. ( curPop), ( curPop).
main ( ) ,
.
. 98% ,
( ),
.
, ,
. ,
,
(), .

main . srand . ,
(
). ( i n i t P o p u l a t i o n ) , ( performFitnessCheck),
(
perf ormSelect ion). , ,
.
,
.
curPop, ;
. ,
( ) - . 6.3.
6.3.
typedef struct population {
float fitness;
int progSize;
i n t program[MAX_PROGRAM];

.

. , ( 6.4).
6.4.
void initMeraberf pop, index )

p o p u l a t i o n s [ p o p ] [ i n d e x ] . f i t n e s s = 0.0;
p o p u l a t i o n s [ p o p ] [ i n d e x ] . p r o g S i z e = MAX_PROGRAM-1;
/* */
proglndex = 0 ;
while (proglndex < MAX_PROGRAM) {
populations[pop]{index].program[progIndex*+] =
getRand(MAX_INSTRUCTION);

} POPULATIONJTYPE;
POPULATIONJTYPE p o p u l a t e

[2]

[MAX_CHROMS];

( MAX_CHROMS), ;
( program),
( p r o g S i z e ) ( f i t n e s s ) . '
p o p u l a t i o n s ( ).

/*
for (index = 0 ; index < MAX_CHROMS
initMember{curPop, index);

_
main i n i t P o p u l a t i o n , ,
, initMember, .

p e r f ormFi tnessCheck
;. 6.5).
6.5.
float maxFitness;
float avgFitness;
float minFitness,-

/* , */
if (result == NONE) {
populations[curPop][chrom].fitness +- TIER1;
}
/* ,
*
*/
if (stackPointer =- 1) {
populations[curPop] [chrom] .fitness += TIER2,-

extern int stack[];

if (stacktO] == answer) {
populations [curPop] [chrom] .fitn

float totFitness;

/*

int performPitnessCheck( FILE *outP )

*/
if (populations[curPop][chrom].fitness > maxFitness) {
maxFitness = populations[curPop][chrom].fitness;
} else if (populations[curPop][chrom].fitness < minFitn
minFitness = populations [curPop] [chrom] . fitness,-

int chrom, r e s u l t , i;
i n t args[10], answer;
axFitness = 0 . 0 ;
vgFitness = 0.0;
1000.0;
0.0;
MAx_CHROMS ; chrom++ ) (
populations[curPop][chrom].fitness = 0.0;

if (outP) {
/*
fprintf(out

for { i = 0 ; i < ; i++ } {


rgs[0] = (rand & Oxlf)
rgstl] = (rand & Oxlf)
: x"3 + 2 + z */
Lswer = (args[0] * a r g s t l ] ) (args[l] * a r g s t l ] )

irgs[2];

i () */
= interpretSTM(populations[curPop][chrom].program,
populations[curPop][chrom].progSize,
args, 3);

*/
%6.4f %6.4f %6.4f\n

p e r f ormFi tnessCheck .
p o p u l a t i o n s .
.

| | :
. , -
, -
, ( 10 ) . !
a r g s .
e v a l u a t i o n . a r g s
-. , -1
.
,
answer , !
i n t e r p r e t s , ( -j
6.1). ,
, . -
. (
), TIER1. , TIER2. , <
( answer), ]!
TIER3. TIERX , TTER3;!
, TIER2, , , , TTER1.T
. -1
-1
. ^
, .
-
, .
maxFitness m i n F i t n e s s .!
t o t F i t n e s s , :]
()
a v g F i t n e s s ) .
1
, - !
. -'
, .

par2 =
; */
childl =
child2 =

rformReproduction( parl, par2, childl, child2

. p a r l 2 ,
c h i l d l c h i l d 2 - .
c h i l d . s e l e c t P a r e n t .
performReproduction,
(. 6.7).
6.7.

int selectParent( void )

j = 0.0;
/* <
do {
/* ]
retFitnes


-

6.6.
6.6.

int performSelectionl void )

if

*/
(populations[curPop][chrom].fitness / maxFitm

if (chrom MAX_CHROMS) chrom = 0;


/* 1
*
*/
(populations[curPop][chrom].fitness > minFitnes;
if (getSRandl) < r e t F i t n e s s ) {
r e t = chrom++;
r e t F i t n e s s = populations[curPop][chrom].fii
break;

} while (1);
MAX_CHROMS ; c h r
<

[||

, . ( r e t F i t n e s s ) do. ,
', , [. , ,
. ( 0 1)
. ,
ipo . iae
.
, (.
6.8).
1 6.8.

int nextPop = (curFop == 0) ? 1 : 0;


int mutate! int );
/* Ecra
if (gel

;
itRand(MAX(populatic
populatii

s[curPop][parentA].progSize-2,
s[curPop][parentB].progSise-2))

) els.
sPoint

= MAX_PROGRAM;

}
)

for ( i = 0 ; i < crossPoint ; i++) {


popu.lationsInextPop][childA].program[i] =
mutate(populations[curPop][parentA].progr;
.lations[nextPop][childB].program[i] mutatelpopulations[c,urPop] [parentB] .progr.

/* */
populations[nextPop][childA].progSize =
populations[curPop][parentA].progSize;
populations[nextPop][childB].progSize =
populations[curPopl[parentB].progSize;
return 0;
}

. , XPROB, ( c r o s s P o i n t ) ( -, ). (
).
( ). ,
.
- . , - .
( f o r ) ,
- ,
, for , ( ).
, . ,
.
, nextPop c u r Pop. nextPop , ; curPop , .
, mutate, , ( 6.9).
6.9.

float temp = getSRandO;


for ( ; i < MAX__PROGRAM ;'i++) (
popi .lations[nextPop][childA].program[i] =
mutate(populations[curPop][parentB].progri

j]|||

ns[nextPop)[childB].program[i] =
efpopulationsEcurPop][parentA].progr.

[ ,
1

II

i||l

> MPROB) (
= getRand(MAX_INSTRUCTION);
irMutations++;

:
DUP DUP MUL MUL SWAP DUP MUL SWAP ADD SWAP SWAP ADD
( D U P DUP MUL MUL)
x . ; .
DUP MUL 2. ,
. ,
SWAP , .
. 6.11
6.5.
. 10000
20000 . , . (2510) 30000 ,
.
3


. -1
, I
( stats.txt), .
,
, 6.2:

(6.2) {

:
DUP MUL DUP MUL DUP MUL

, 1
, - . |
DUP.

6.3:

<6.3) j

( 2) + ( 2) + z

ADD DUP ADD SWAP ADD

, .!
, 2 ( DUP 1
ADD). ADD z. , 1
SWAP, , - |
.
6.4:
(

(6.4)

:
OVER ADD MUL ADD

(), noi
. . -
, ADD z. ;
() .
6.5:
3

(6.5)

(1 = 100 )
. 6.11. 6.5

III11


'
^, .), . , - 1
, . -|
, |
( ). 1
|
.

: , , -
. , |
ITO . - |
, , - |
(, !
10%) .
, - ]
. , . .]
, . , ,!
, .

-
. , -'
, . -1
, , 1
|
, .

>. ,
.
.

. ,
> .
inversion), .

IEES

, . , , .
(
), .
,
. .
(R. Hollstein) (. 6.5).
6.5. , . (
)

-
/ . (Thomas Back) .
, .

.
, , . ,
, .
( ), .
- , 70%

__
, - |
.
, , Hei
. - 1
:
: .


. |
, . ;


- |
. \
1 , , - |
. -.
1 , - |
. , , !
.
|
. - ',
> . , |
; .
, - j
[ . , |
[ , . -.
: , - |
.

(1), . -.
i , , .
, .
, ([), . ,
| , , .


* ,
.
, ,

.


.
, , . , , .
:
;
;
;
.
,

. ,
.

. - ,
, . , , . ,
- ( ), . ,
, ,
.

Hill


1. . , !
(Back . The Interaction ofi
Mutation Rate, Selection, and Self-Adaptation within a Genetic Algorithm. 1
Germany: University of Dortmund, 1992).
2. . Web- Genetic Programming Inc.. http;//www.genetic-programn
com.
3. . : -]
(Koza J. Genetic Programming:"!
On the Programming of Computers by Means of Natural Selection. - Cambrid}
Mass.: MIT Press, 1992).
4. . (Holland J. Concerning!
efficient adaptive systems // Self-Organizing Systems.- Washington, D.C.: S p a r t a n !
Books, pp. 215-230, 1962).
5. . (Holland J. j
, Adaptation in Natural and Artificial Systems. Ann Arbor: The University of 1
Michigan Press, 1975).
6. . - 1
(Hollstein R. Artificial Genetic Adaptation in Computei
Control Systems. Ph.D diss., University of Michigan, 1971).
7. . I
(Shaffer R. Practical Guide to Genetic Algorithms, 1993). |
http://chemHiv-www.nrl.navv.mil/fi110/6112/sensors/chemometric:

7.
(Artifical life) - ,
(Chris Langton) ,
.
,
, . , , .

. - (Synthetic ethology). (Bruce


MacLennan):
4 - ,
. , , , .
. . , , ,
, . ,
,
.



. ,
, (. 7.1).
.
(, ). , - . .

. 7.1.

____^ _
, . , ,
, 7.1.
. 7.1 , , -1
. , -|
?
,
.
!
.


, : ( ,
), (
) , , i
. .

, _
. >1
. ^

. , ^
. ,
. -
, . ^ -|
, . , -J
. , -1
( ).
, ,
. , .
, , . "
.
.

. 7.2. , ,
.


.
( ), (.
. 7.3).
)

( ),
)

( ) .

] -

1 -


, , -
. -'^
, (. 7.2).
, -|
( / ).

. 7.3.

144

. 7.3, . , ( , ) .
, . |
. *
, . .

- (1744-1829)
, , - j
., - \
,
, .

, . .
, (. 7.4).
, , . , , (,
). (5 ) ,
.

:
,

145

(, ), .

:
{ ),
, - , , ,
.


. , . ,
, ^ (. 5), . . 7.5 .
, , .
, * . 7,1:

oj - + ._0 u.w.,

(7,1)

, () (),
(w,.), . , .
. .

>

\ |

|81||

. 7.4. .

, ,
. . .
( ), .


, .
, . , . ,
. ,
-409

146


.......^.........v. .

, - . ,
, .
, . ,
, .
.

147

. 7.5. :

- . ,
.

, 90% , . ,
, ( ).
. , ,
, . ,
(
).
: ( ).
.

: , , .
.

. ,
.
, . ,
. , .


, .
,
. 300 ,
, . . 7.6
.

,
. ^ ^ (
, ).
, ,
> . .
. ( ). , . 7.6.
( 7.1), ( ) , ,
, . 7.7. (
. 7.4). X (
). , <*.

149

HF CF PF
{ 1 , 0, 0,
{0, 0, 0,
{0, - 1 , 0 ,
{1, 0, 0r

HF CL PL HR
0, 0 r 1, 0,
0 , - 1 , - 1 , 0,
0 , 1, 0 , 0 ,
0, 0 , - 1 , - 1 ,

CR
0,
0,
0,
0,

=
=
=
=

1
0
1
0

-i- 0 = 1

-1 = -1
- - 1 = 0
- 1 = 1

PR HR CR PP
0 , 0, 0 , 0}
0, 0, 0, -1}
0 , 0 , 0 , 0}
0, 0, 0, 1}

1
0
1

0
= {0, 1 , 0 , 0 , 0, 0 , 0 , 0 , 0 , 0, 0 , 1}
. 7.7, t0

. 7.6.

, - .

,
. , 7.7, / (HF ^, CF -

, - * ..)' :
, : -|
*&> ^.
, , !
, *
. , 7.7. -j
.
, . ?
( ).
, . ,
, . 7.8.

=
=
=

1
0
1
0

+
+
+
+

0 = 1
0 = 0
-1 = 0
0" = 0

=
=
=
=

1
0
1
0

+ 0 = 1
+ 0 = 0
+ 0 = 1
+ - 0

HF CF PF HF CL PL HR CR PR HR CR PP
U , 0 , 0 , 0 , 0 , 1 , 0, 0 , 0 , 0, 0 , 0}
{0, 0 , 0 , 0 , - 1 , - 1 , 0 , 0 , 0 , 0 , 0 , - 1 }
{0, - 1 , 0 , 0 , 1 , 0 , 0 , 0, 0 , 0, 0 , 0J
{1, 0, 0, 0, 0 , - 1 , - 1 , 0, 0, 0, 0, 1}

HF CF PF HF CL PL HR CR PR HR CR
= U , , , , ", 1, 0, 0, 0, 0, 0, 0}
= {0, 0, 0, 0, -1,-1, 0, 0, 0, 0, 0, -1)
= {0, -1,0, 0, 1, 0, 0, 0, 0, 0, 0, 0}
= {1, 0, 0, 0, 0,-1,-1, 0, 0, 0, 0, 1}

, 1, 0, 0, 0 0, 0, 0 0, 0, 0, 0}

. 7.8.

, , . (
). |
, . - ]
? ^^. , ]
1.
, . 7.9 . , ,
.

1
0

= { 0 , 0 , 0 , 0 , 0 , 0 ,

0,

1,0,

0,

0,

0J

. 7.9. 2

. ^>,
.
, > , , .
, , . ,
.

,
* * www.dmk.ru.

.
, , .


7. i , -1
. : t y p e -1
, energy -1
, age - , g e n e r a t i o n -1
, ,
.
( locType) !
. i n p u t s
. a c t i o n s co-J
, .!
, w,eight_oi ( ) b i a s s o - |
.

typedef
s h o rt
s h o rt
sho rt
sho rt

struct {
type,energy;
parent;
age;

s h o rt inputs[MAX_INPUTS];
s h o rt weight_oi[MAX_INPUTS
s h o rt biaso[MAX_OUTPUTS];
s h o rt actions[MAX_OUTPUTS];
} agentType;

MAX_OUTPUTS];

'

0
1
2
3
4

. ,
(, ). - ,
. 7.3 , .
7.3.
#define HERB_PLANE
#define CARH_PLANE
#define PLANT_PLANE

0
1
-1

typedef struct {
short y_offset;
short x_offset;
} locType;

#define MAX_GRID

1
2
30

/* ( ,

(, -1
). -1
, , i
, 1
. 7.2 "]
.
7.2.
#define HERB__FRONT
#define CARN_FRONT

ACTION_TURN_LEFT
ACTION_TURN_RIGHT
ACTION_MOVE
ACTION_EAT

ttdefine MAX_OUTPUTS

locType location;

tdefine TYPE_HERBIVORE
#define TYPE_CARNIVORE
#define TYPE_DEAD

tdefine MAX INPUTS


#define
#define
#define
#define

7.1.

)!![]

Idefine PLANT_FRONT
#define HERB_LEFT
#define CARN_LEFT
idefine PLANT_LEFT
#define HERB_RIGHT
itdefine CARN_RIGHT
#define PLANT_RIGHT
#define HERB_PROXIMITY
#define CARN_PROXIMITY
define PLANT_PROXIMITY

*/
int

landscape[3][MAX_GRID][MAX_GRID];

#define MAX_AGENTS
#define MAX_PLANTS

36
35

agentType agents[MAX_AGENTS];
i n t agentcount = 0;
plantType plants[MAX_PLANTS];
i n t plantCount = 0;

H i l l ? . J?!ffi!!*_*"?!!b _
, - - 1
), . 1
common. h , -1
1.
, , I
, (- I
J
:
7.4).
17.4. , ,

i n i t (,
). ,
. , i n i t Agent
. i n i t Agent , , ( 7.6).
7.6. init

(float)RAND_MAX)
getRand(x) ( i n t ) ( ( x ) * getS a n d O )
/* */
getSRand 0 1, g e t - |
land - 0 - 1 . getWeight , |
1 . - i
, .
. |
main, - J
; .
main , - |
, MAX_STEPS. s i m u l a t e [, {
7.5).
1 7.5. main
int main ( int argc, char *argv[]>

bzerof

(void *)landscape,

sizeof(landscape)

);

bzero(

(void *)bestAgent,

sizeof(bestAgent)

);

/* */
}
if (seedPopulation == 0) {
/* */
for (agentCount = 0 ; agentCount < MAX_AGENTS ; agentCount++) {
if {agentCount < (MAX_AGENTS / 2}) {
agents[agentCount].type = TYPE_HERBIVORE;
} else {
agents[agentCount].type = TYPE_CARNIVORE;

initAgent(

Sagents[a

/*
srand< time(NULL) );
/*
init();
/* */
for (i - 0; i < MAX__STEPS ;

. , MAX_PLANTS.
g r o w P l a n t s ( 7.7).
. (
MAX_AGEHTS), . , .
i n i t A g e n t ( 7.8).

111

1;|

growPlant -J
( 7.7). ,
( .
).
7.7. growPlant
1
void growPlant( int i )
{
i n t x,y;
while (1) {
/* */
- getRand(MAX_GRID); = getRand(MAX_GRID);
/* */
if (landscape[PLANT_FLANE][][] == 0) {

7.8. ini tAgent,

agent->energy = (MAX_ENERGY / 2);


agent->age = 0;
agentTypeCounts[agent->type]++;
findEmptySpot( agent );
or (i = 0 ; i < (MAX_INPUTS * MAX_OUTPUTS)
agent->weight_oi[i] = getWeightO,for (i = 0 ; i < MAX_OUTPUTS ; i+
a g e n t - > b i a s o [ i ] = getWeight();

/* */
plants [i] . l o c a t i o n . x = ,p l a n t s t i ] . l o c a t i o n . - ;
landscape[PLANT_PLAlffi][][]++;
break;
void findEmptySpot( agentType *agent )
agent->location.x - - 1 ;
agent->location.y = - 1 ;
while (1) {
( 7.8). -1
, ( 7.6). -,
, . e n e r g y
! . , , ). , , ,
. , - |
. a g e n t T y p e C o u n t s
. , S - ]
50/50 . - >
iee f indEmptySpot ',
| ( 7.8). ( ) . !, .

/* */
agent->location.y = getRand(MAX_GRID);
/* ,
if (landscape [agent->type]
[agent->location.y]
break;

agent->direction = getRand(MAX_DIRECTIOH);
landscape[agent->type][agent->location.y][agent->loca

j||;

11

, f indEmptySlot -1
. , -1
. , -^
l a n d s c a p e , .
, , !
. , main ( 7.5) -1
s i m u l a t e , . s i m u l a t e ( 7.9)1
!
. , , - .
, -|
, ,
.
7.9. simulate
void simulate; void )
{
int i,

type;

/* */
for (type = TYPE_HERBIVORE ,- type <= TYPE_CARNIVORE ; type++) {|
for (i = 0 ; i < MAX_AGENTS ; i++) {
if (agentsfi].type == type) {
simulateAgent( &agents[i] );

s i m u l a t e ( 7.9) simulateAgent !
. - |
. , ;
, .
, , - !
. (. 7.4), 1
(, , >
). , , (
),
.

||||

s i m u l a t e A g e n t ( 7.11). ,
. p e r c e p t . , (HERB_< >) ( , , ,
).
p e r c e p t ,
i n p u t s , o f f s e t s .
, , north<zone>, , , - 1 . west<zone>.
,
.
, 7.10.
7.10.

const offsetPairType northFront[]=
{{-2,-2}, {-2,-1}, {-2,0}, {-2,1}, {-2,2}, {9,9
const offsetPairType northLeft []={{, -2}, {-1,-2}, {9,9}};
const offsetPairType northRight[]={{0,2}, {-1,2}, {9,9}};
const offsetPairType northProx[]=
{{0,-1}, {-1,-1}, {-1,0}, {-1,1}, {0,1}, {9,9}};
const offsetPairType westFront[]=
{{2,-2}, {1,-2}, {0,-2}, {-1,-2}, {-2,-2}, {9,9}};
const offsetPairType westLeft[]={{2,0}, {2,-1}, {9,9}};
const offsetPairType westRight[]={{-2,0}, {-2,-1}, {9,9}};
const offsetPairType westProx[]=
{{1,0}, {1,-1}, {0,-1}, {-1,-1}, {-1,0}, {9,9}};
,
. n o r t h R i g h t .
, <7,9> ( <,>). n o r t h R i g h t ,
- <7,11> <6,11> ( <9,9> ). , . , n o r t h R i g h t ,
. :
<7,7> <8,7>.
, .
, si mulateAgent ( 7.11).

[out];

1 7.11. simulateAgent

for ( in = 0 : in < MAX_INPUTS ; in++ ) {


agent->actions[out] +=
( agent->inputs[in] *
agent->weight_oi [ (out * MAX_INPUTS)+in] ) ;
/*
= agent->lO'
= agent->loi
switch( ,

largest = -9;

nt->di: ectii

:ase NORTH:
percept; x, y, &agent->inputs[HERB_FRONT], northFront, 1 );
percept] x, y, &agent->inputs[HERB_RIGHT], northRight, 1 |;
percept! x, y, &agent->inputs[HERB_PROXIMITY], northProx, 1);
break;
:ase SOUTH:
percept! x, y,
percept! x, y,
percept! x, y,
percept! x, .
break;
:ase WEST:
percept!
percept!
perceptt
percept!
break;

x,
x,
x,
x,

&agent->inputs[HERB_FRONT], northFront, -1 ),&agent->inputs[HERB_LEFT], northLeft, -1 1;


&agent->inputs[HERB_RlGHT], northRight, -1 );
&agent->inputs[HERB_PROXIMITY], northProx, -1 I;.

y, &agent->inputs [HERB_FRONT] , westFront, 1 ) ,y, &agent->inputs [HERB_LEFT] , westLeft, 1 ) ,y, &agent->inputs[HERB_RIGHT], westRight, 1 );
y, &agent->inputs[HERB_PROXIMITY], westProx, 1 |;

:ase EAST:
percept! x, y, &agent->inputs[HERB_FRONT], westFront, -1 );
percept! x, y, &agent->inputs[HERB_LEFT], westLeft, -1 );
percept! x, y, bagent->inputs[HERB_RIGHT], westRight, -1 );
percept! x, y, &agent->inputs[HERB_PROXlMITY], westProx, -1 );
break;

/* i
for ( out = 0 ; .

('

/* i
* )
= 0 ; out < MftX_OUTPUTS ;

+ ) (

largest = agent->,

fitch! '

:
- ) {

;ase ACTION_TURN_LEFT:
;ase ACTION_TURH_RIGHT:
turn! winner, agent );
break;
:ase ACTION_MOVE:
move{ agent );
break;
:ase ACTION_EAT:
eat( agent );
break;

/* "" */
if (agent->type == TYPE_HERBIVORE) {
agent->energy -= 2
} else {
' .
agent->energy -= 1;

: MAX_OUTPUTS ;
:

i - <


,
if (agent->energy <= 0) {
killAgentt agent ) ,} else {
agent->age++;
if (agent->age > agentMaxAge[agent->type]) {
agentMaxAge[agent->type] = agent->age,agentMaxPtr[agent->type] = agent;

,
s i m u l a t e A g e n t .
, * i n p u t s , ^
. !
7.1. ,
!
. ( ,
) ,
, .
c a s e . 7.11, !
: ACTION_TURN_LEFT, ACTION_TURN_RIGHT, AC
ION_TURM_MOVE ACTTON_EAT.
- . 1
( ;
). ,
. , , (
, k i l l A g e n t ,
.
, s i m u l a t e A g e n t , i
, ( p e r c e p t , t u r n , move, e a t k i l l A g e n t ) . J
, p e r c e p t s !
, , , 7.12, , . *!
, ;
.
7.12. percept

-lane, i;
:off, yoff;

or (plane = HERB_PLANE ; plane <= PLANT_PLANE ; pla;


* */
nputs[plane] = 0;
. = 0;
/* */
while (offsets[i].x_offset != ) {
/*
xoff = + (offsets[i].x_offset * neg);
yoff - + ( o f f s e t s ! ! ] . y _ o f f s e t * negj;
xoff = clip< xoff i;
yoff = c l i p ! yoff };

if (landscape[planenyoff][xoff] != 0) {
inputs [plane]++,-

int clip! int z )


if (z > MAX_GRID-1) z = (2 % MAX_GRID);
e l s e i f ( z < 0 ) z = (MAX_GRID + z ) ;

, p e r c e p t
. p e r c e p t .

( ).
.
, i n p u t s ,
. , ,
; , ,
, .

7.12 c l i p , percept, .
turn, 7.13, , , .
.
7.13. turn

j | | | |
7.14. move
void move! agentType *agent )
{
/*
*
*/
const offsetPairType of fsets [4] ={ {-1, 0}, {1, 0}, {0 ,1}, (0, -1}},-

void turn ( int action, agentType *agent )


{
/*
*

/* */
landscape[agent->type][agent->location.y][agent->location.x]--;
/* */
agent->location.x =
clip( agent->location.x + offsets[agent->direction].x_offset

switch! agent->direction ) {
case NORTH:
if (action == ACTION_TURN_LEFT> agent-direction = WEST;
else agent->direction = EAST;
break;
case SOUTH:
if (action == ACTION_TURN_LEFT) agent->direction = EAST;
else agent->direction = WEST;
break;
case EAST:
if (action == ACTION_TURN_LEFT) agent->direction = NORTH;
else agent->direction = SOUTH;
break;

landscape[agent->type][agent->location.y][agent->location.x]++;
}
e a t :
( ), ( 7.15).
7.15. eat
void eat( agentType *agent )

case WEST:
if (action == ACTION_TURN_LEFT) agent->direction = SOUTH;
else agent->direction = NORTH;
break,-

move .
, , , . 7.14 . p l a n e (
" type), . i , , 1 .

);

agent->location. =

if

(agent->type

/*
ax = agent->lo
ay = agent->lo

, */
E_CARNIVOREJ plane = HERB_PLANE;
= TYPE_HERBIVORE) plane = PLANT_PLANE;

t */

/* '

^ 1_

agent->energy += (MAX_FOOD_ENERGY*2);
' if (agent->energy > MAX^ENERGY) agent->ei rgy = MAX_ENERGYk i l l A g e n t l &agents[i] ) ;

:hooseObject( p l a n e , ax, ay, northProx, - l ,

break;
:ase WEST:
ret = chooseObject( plane,
break;

:tProx, 1, &ox. Soy ] ;

:ase EAST:
break,-

X, -1, &QX, &oy );

/* if (ret) {

*/
if (agent->energy > (REPRODUCE__ENERGY * MAX_ENERGY)) {
if (noRepro == 0) {
reproduceAgent( agent );
agentBirths[agent->type]++;

int i;
if (plane == PLANT_PLANE) {
/* */
for (i = 0 ; i < MAX_PLANTS ; i++) {
{plants[i].location. == oy))
break;

if

(i < MAX_PLANTS) {
agent->energy += MAX_FOOD_ENERGY; if (agent->energy > MftX_ENERGY) agent->energy = MAXJMERGY;
landscape[PLAMT_PLANE] [oy] [ox] ;
if {noGrow == 0) {
growPlant( i ) ;

} e l s e i f (plane == HERB_PLANE) {
/* ( ) */
f o r (i = 0 ; i < MAX_AGETS ; i++) {
if ( ( a g e n t s E i ] . l o c a t i o n . x == ox) && .
( a g e n t s [ i ] - l o c a t i o n . == oy))
break;

, . , .
, , -
( ).
, , c h o o s e O b j e c t { 7.16),
. ,
( 7.11), *- . , c h o o s e O b j e c t , , / e a t .
7.16. chooseObject
int chooseObject( int plane, int ax, int ay,
const offsetPairType *offsets,
int

off, yoff, i=0;

/* */
while (offsets[i].x_offset != 9) {
/* */
xoff = ax + (offsets[i].x_offset * neg);

^"^

XOff = Clip( XOff );


yoff = c l i p ! yoff );
,
ape[plane][yoff][xoff] < = 0] {
= xoff; *oy = yoff;

void killAgent( agentType *agent )


{
agentDeaths [agent->type] ++,/* ( ) */
agentTypeCounts{agent->type]==;
if (agent->age > bestAgenttagent->type].age) {
memcpy{ (void *)sbestAgent[agent->type],

if (agentTypeCounts[agent->type] <

c h o o s e O b j e c t p e r c e p t ( 7.12), |
, , , .
- . ,
, . -
p l a n t s , :
l a n d s c a p e . , )
. :;1
a g e n t s -- ]
> k i l l A g e n t ( 7.17). - j
1 .
, , - \
, r e p r o d u c e A g e n t , ( 7.18).
'
, , , 1 . -
(
). ( ) - :
, .
, ( ) .
, . ,
,
.
, 25%
. 25%
.

7.17. killAgent

(MAX_AGEUTS / 4)}

initAgent( agent j ;

agent-location, = - 1 ;
agent->type = TYPE_DEAD;

, r e p r o d u c e A g e n t , , . , . ,
. ,
. r e p r o d u c e A g e n t 7.18.
7.18. reproduceAgent
void reproduceAgent( agentType *agent )
{

agentType

*child;

!entTypeCounts[agent->typel

<

(MAX_AGENTS

/ 2))

H U H '
/*
* ]
if

-f

MAX_AGENTS ; i++) {
.type == TYPE_DEAD) break;

(a

(i < MAX_AGENTS)

. , :

child = Sagents[i];
memcpyf

(void * ) c h i l d ,

(void *)agent, size

findEmptySpott child ];
if (getSBandl) <= 0.2) {
child-?weight_oi[geCRand(TOTAL_WElGHTS)]

getWeight();

child->gene
child->age
if

/*

;||

TOTAL_WEIGHTS.
, ( ). , , ,
.

, common. h. common. h 36 (18 18 ), 30 30x30.


1 . . 7.10
,
.
.
, ,

(agentMaxGen[child->type] < child->ge


agentMaxGen[child->type] = child->gene

child->energy = ag


(MAX_EKERGY

agentTypeCounts[child->type]++;
agentTypeHeproductions[child->type]+

, , , 50% .
,
,
( ).
, -
, , .
. , , .

!
250

200

I1

100

50
i

00

100000 200000 300000 400000 500000 600000 700000 800000 900000 1+06
. 7.10.

,
.
. ,
, .
( ) a g e n t s . d a t . . , p l a y b a c k .
, . :

, | , . , | . ,
- , ,
| . , I . , .
, . 7.1.
| 7.1.

{
agenls.dat)
( runtime.dat)

'

( Enter)

./sirr - p r n
, p l a y b a c k .
, ,
, p l a y b a c k ,
( ).
, , (. 7.11).
/
1,4

"
*

-

1,2

: , .


0
0,8
0,6
0,4

?}
1
*

, , .
- . ,
. , , , . , ,
s. . ,
, , .

0.2

0 ;
20

40

100

120

140

160

180

. 7.11. playback. , -
,

, - , . ,
, , (
). ,


, . , .
, .
common. h.
,
. 7.1.

. .

- ,
.
/
.
.


l.CALResCa (The Complexity & Artificial Life Research Concept for
Self-Organizing Systems). http: //www.calresco.org.
2. Digital Life Lab at Caltech. Aveda (Aveda Software). http://dllab.calterh.edii/vid a.
3. . (Langton . What Is Artificial
Life). http://www.biota.org/papers/cgalife.html.
4. . (MacLennan . Bruce
MacLennan's Home Page), http://www.cs.utk.edu /-mclennan/.
5. .
(MacLennan . Artificial Life and Synthetic Ethology).
http://www.cs.utk.edu/~mctennan/alife.html.
6. . Web- International Society for Artificial Life, http://www.alife.org.

8. ,

:
, , .
( ),
i '. ( ) , :
| , . ,
. ;
j , ,
[ , .

, , MI
| (Production rules).
|' . (
1 , . (
jf TO) .
| : (
)
.

, , !
| , ,
! . , , >
;- ( ).
\ ( ). . 8.1
? , .
, .
, ; :
' , .
, .

, | | | | |

defrule , .
.
- , (sensor-failed sensorl). ;
=> .
. npt
. ,
. - ,
, - , . npi
(disable
sensorl).

. 8.1. ,

(Working memory) ,
. , ( ,
). :

, ,
. -
. .

(s.

(mode nori

, ,
, .
- (. ,
).

al)

. - . , s e n s o r - f a i l e d , s e n s o r l . , s e n s o r l . , mode n o r m a l . ( , ,
).

(Knowledge base) , .
. , , . ,
. :

(Backward chaining)
, , ,
. :
, ()
.
. , ;
, 1
.
. ,
.

(Forward chaining) .
. ,
, , ,
. ,
. ,
, (
) .

178

, ,
( ), , , ;
, .

, .

, , (. 8.2).

(Action phase)
. ,
. , ,
, - ,
(, .
).



. ZOOKEEPER,
(Patrick Henry Winston),

.
( 8.1).

i-

>

8.1. , ZOOKEEPER

{defrule bird-test
thas-feathers ?)
=>

{bird ?)

(defrule mammal-test
(gives milk ?>

. 8.2. ,

(mammal ?)


(Match phase)
.
, . ,
, .
, - .


(Conflict resolution phase)
, , .
, . , .

(defrule ungulate-testl
(mammal ?)
(chews-cud ?)

=>

{is-ungulate ?)

(defrule ungulate-test2
(mammal ?)
(has hoofs ?)
=>
is-ungulate ?

HUP

,
(gives-i
(has-ho<

.mal)
al]

, .
( b i r d - t e s t ) ,
(mammal-test). , . , . ,
mammal-test ( ), :
(gives-milk
(has-hoofs a
(mammal aiT-irp

|||

.mall
lal)

.
, mammal-test u n g u l a t e - t e s t 2 . , . ( u n g u l a t e - t e s t 2 ) .
; , , .
u n g u l a t e - t e s t 2 :
(gives-milk ani al)

, , ycrof
, ,
( ).



| . ,
. ,
, .
" , . ,
| ,
.
(. 8.3).
|. , : ]
t . [!
| (, ;
). , j
I'.

(has-hoofs anim l )
(mammal animal)
(ungulat
l)
,
. , ( ), , ,
, .
. . , ,
. , .

. 8.3.

___ _ _ _ _ _ _


, .

(defrule failure
(mode normal!
(sensor-failed sensorl)
(sensor-failed sensor2)


8.2.
(), .
8.2.
(defrule i n i t
(true null)

(add (sensor-active none))


;
(add (sensor-working sensorl))
(add (sensor-working sensor2))
(add {mode normal))
(enable (timer 1 10))
(print (-default rule fired!"))
(disable (self))
)

(add (mode failure)!


(delete (mode safe))
(delete (mode normal))
)
;
(defrule triggerl
(Cimer-triggered 1)
->
(print ("Sensor 1 failure.\n"))
(add (sensor-failed sensorl))
(enable (timer 2 10)]
(delete (timer-triggered 1))
)
(defrule trigger^
(timer-triggered 2)

;
(defrule sensor-failed
(sensor-working ?)
(sensor-failed ?)
)

(delete (sensor-working ?))

(print ("Sensor 2 failure.\n")|


(add (sensor-failed sensor2))
(enable (timer 3 10))
(delete (timer-triggered 2))
)
(defrule trigger3
(timer-triggered 3)
(print ("Sensor 1 is now working.\n-))
(delete (sensor-failed sensorl))
(add (sensor-working sensorl))
(enable (timer 4 10))
(delete (timer-triggered 3))

(sensor-failed ?)

(delete (sensor-active ?))


(add (sensor-active none))

(defrule make-working

)
(defrule trigger4
(timer-triggered 4)
(print ("Sensor 2 is now working.\n"))
(delete (sensor-failed sensor2))
(add (sensor-working sensor2>)
(enable (timer 1 10))
(delete (timer-triggered 4))

(add (sensor-active ?))


(delete (mode failure))
(add (mode normal))
)

[|(^_

, . 8.2 ( i n i t ) . , ( t r u e n u l l ) .
( add). e n a b l e , . (), ,
(. 8.3).


Microsoft, .

t i m e r , , ( 1 10 ). p r i n t
. , d i s a b l e , .
. ,
, (,
init).
i n i t , :
(sensor-working sensorl)
(sensor-working sensor2)
(mode failure)
make-working ( sensorl). :
(sensor-working
(si

sensorl)
2)
1)

(mode normal")
, ( 10 ). : ( t i m e r t r i g g e r e d 1). ,
( ). , , s e n s o r l .
:

;|||

(mode normal)
sensor-failed check-active. ;
:
(sensor-working
(sensor-failed

sensor2)
sensorl)

, make-working.
:
(sensor-working sensor2)
(mode normal)
(sensor-failed sensorl)

.
(
mode).
.


, ,

* dmk.ru.

, ,
.
. 8.4.
()
, . ;
,
, . ,
. , ,
, .
, .

, (
8.3).
.. ,
define MEMORY_ELEMENT_SIZE 80
define MAX_MEMORY_ELEMENTS 40

HI

j||||l

IDS

memoryElementType
memoryElementType !
} ruleType;
typedef struct {
expirat
} til rType;

memoryElementType
I , .
I element . ruleType
| . a c t i v e ,
| . ruleName (
| def r u l e ) . , ,
I , .

a n t e c e d e n t consequent
I . , memoryElementType
next, !
| ( , - ). timerType
. a c t i v e ,
|., . e x p i r a t ion
, .
8.4 ,
. ,
.
^ . 4.
memoryElementType workingMemory[MAX_MEMORY_ELEMENTS];
. 8.4. ,
#define MAX_RULES
#define MAX_TIMERS
typedef s t r u c t memoryElemi
typedef s t r u c t memoryElemi
char element[MEMORY_ELEMENT_SIZE+1];
s t r u c t memoryElementStruct *next;
} memoryElementType;
typedef s t r u c t

char ruleName[MEMORY_ELEMENT_SIZE+l] ;

ruleType ruleSet[MAX_RULES];
timerType timers[MAX_TIMERS];
. endRun
. debug 0;

workingMemory, r u l e S e t t i m e r s
f ( 8.3). : endRu
' ( q u i t
; debug (,
).
main ( 8.5) ,
-.
( g e t o p t ) . !
h ( ), d (

1111 ^ ^ ?
) (, ). , , ( ),
.
,
a c t i v e . p a r s e F i l e ( 8.6), r u l e S e t .

while (1)

if

8.5. main ,
int main! int argc, char *argv[]

i n t e r p r e t ;
(debug) {
printWorkingMemory();

char inpfile[80] = {0},-

if

extern void processTimers(

(endRun)

break,-

sleep(l);

while ({opt = getopt(argc, argv, "hdrr")) != -1) {


. switch( opc ) {
case 'h':
emitHelpO;
break;
case 'd':
debug = 1;
printf("Debugging enabled\n");
break;
strcpy(inpfile, optargl ,break;

main, 8.5. -,
i n t e r p r e t . , I V H H .
,, p r o c e s s T i m e r s . q u i t ,
^ ( endRun).
. , ' s l e e p ( ,
|. ). , , , p r o c e s s T i m e r s ,
| .
( p a r s e F i l e , 8.6) , I , -. ,
1 .
| , :
(defrule <rule-name>

if (inpfile[0] == 0] emitHelpO;
bzerol (void *|workingMemory, siz
bzerot (void *) timers, sizeofttiin
ret = parseFilel inpfile ) ,if (ret < 0) {

f <workingMemory) );
Set) );
s) I ;

(consequent-terms)
)
d e f r u l e .
, . =>, . ) . ,
; , 8.2.

j||HH

. , .
-, .
, , , . ,
. 8.6
s k i p W h i t e S p a c e , , , , .

while (*cur != OxOa) {


ruleSet[rulelndex].ruleMame[i++] = *cur++}
ruleSet[rulelndex].ruleUame[i++] - 0;
cur = skipWhiteSpace( cur ) ,-

.6. - ( \eFile)

if (cur == NULL! {
fail - 1;
break;

/* */
cur = parseAntecedent ( cur, &ruleSet [rulelndex] ) ,-

FILE *fp;
int fail = 0;
extern int debug;
file = (char *)raalloc(MAX_FILE_SIZE);
-1;

/* "=>" */
if (!strncmp(cur, =>", 2)) {
cur = skipWhiteSpace( cur+2 );
/* */
cur = parseConsequent( cur, bruleSet[rulelndex] );
if (cur == NULL) {
fail = 1;
break;

fp = fopen(filenam
if (fp == NULL) {
free(file);
return -1;
freadf file, MAX_FILE_SIZE, 1, fp);

/* , */
if <*cur == )') {
cur = skipWhiteSpace( cur+1 );
} else <
fail - 1;
break;

cur = &file[0];
while (1) {
/* */
/* ( "(defrule" */
cur = strstrl cur, "(defrule" );
if (cur == NULL) {
fail = 1;
break,-

) else {
fail = 1;
break;
ruleSet[rulelndex].active = 1;
rulelndex++,} else {
break;

I l l l l t
if (debugI

}
free(

[void * ) f i l e );

fclose(fp);

.. *** 0. :||

_.____.

skipWhiteSpace
I .
| .
p a r s e E l e m e n t ,
I ( ).
I ,
|' ( ).
I ( 8.8).
I 8.8. parseElement

.( ) - .
8.7.
p a r s e E l e m e n t .
8.7. -
char *parseAntecedent t char *block, ruleType *rule )
{
while (1) {
block = skipWhiteSpace( block );
if (*block == C) {

mem oryEleme ntType * ele'ment;


balan

= 1;

ele
(inemoryEleme ntType* Jmallo.c(si;
element > el ement[i*
= *bloi=k++;
1

loryElementType)) ;

while (1) (
f (*block == 0) bre
if (*block == ' ) ' ) balanci
if (*block == ' ( ' i balanci

} else break;
eturn block,^eConseguentt char "block, ruleType *rule )

element->element[i] = 0;
if (*met == 0) *met = element;

if (*block == ' i {

memoryElementType *chain = 'met;


while (chain->next != 0) chain = chain->next,-

block = parseElement(block, &rule-x


} else break;

, skipWhiteSpace . ,
; , ( 8.9).


8.9. ,
char *skipWhiteSpace(
{
char ch;
while

(1)

char

*block

fired = checkRulel rule );


/*
* .

if (fired) break;

ch = "block,w h i l e ( ( c h != ( ' ) && ( c h != ' ) ' ) && ( c h != ' = ') &&


( c h 1= 0) && ( c h ! = ; ' ) ) {

} else break;

if (debug) {
if (fired) printf("Fired rule %s (%d)\n",
ruleset[rule] .ruleName, rule);

c h e c k R u l e ,
!> , (
I 8.11). c h e c k P a t t e r n ,
|.
~^8.11. checkRule

r u l e S e t
. , 8.5,
i n t e r p r e t ( 8.10).
checkRule, . checkRule
, , . ,
.
. 10. interpret

extern i n t checkRulel i n t );
extern int debug;
for (rule = 0 ; rule < MAX_RULES ; rule++) {
fired = v 0;

int checkRulel int rule )


char arg[MEMORY_ELEMENT_SIZE]={0};

fire = checkPattern(rule, arg);


if (fire == 1) (

c h e c k P a t t e r n
. , f.
reRule. , ,
f i reRul e.
, ,
.

; | |
( c h e c k P a t t e r n ) , . , , .
, ,
, , , .
,
, .
c h e c k P a t t e r n . ,
, , :

for (i = 0 ; i < MAX_MEMORY_ELEMEbfTS ; i++|


e) {
sscanff workingMemoryfi].element, "(%s %s),
wm_terrol, wm_term2 );
if (wm_term2[strlen(wm_term2)-l] == )-)
wm_term2[strlen(wm_term2J-1] = 0;
n(terml)))
addToChain(wm_term2|;

(defrule
check-fully-charged
(fully-charged?)
( t r i c k l e - c h a r g e ?)
)

mtecedent = a n t e c e d e n t - > n e x t ;

, ( f u l l y c h a r g e d ) , - . :
(fully-cftarged battery-1)

. ,


:
(trickle-charge

battery-l)


, *?. ,
, .
c h e c k P a t t e r n 8.12.
. 12. . cbeckPattern
int checkPattern< int rule, char *arg )
char
char

terml[MEMORY_ELEMENT_SIZE+1];
term2[MEMORY_ELEMENT_SIZE+1];

do (
memoryElementType * c u r R u l e P t r , *temp;

while (curRulePtr) {
s s c a n f ( curRulePtr->element, "(%s %s) n , terml,- term2 );
if (term2[strlen(term2)-l] == )) term2 [strlen(terra2)-1] = 0,if {istrncmp( t e r m l , " t r u e " , s t r l e n ( t e r m l ) ) ) {
r e t = 1;
break;
} else {
if ((term2[0] == '?') && (chain)) {
strcpy(term2, chain->element);
I
}

s s c a n f f a n t e c e d e n t - > e l e m e n t , "(%s % s ) " , t e r m l , t e r r a 2 ) ;


i f ( t e r m 2 [ s t r l e n ( t e r m 2 ) - l ] = = )) t e r m 2 U t r l e n ( t e r m 2 ) - 1 ] = 0 ;

r e t = searchWorkingMemory ( t e r m l , term2 ) ,-

if

if

(term2[D)
char
char

==

?')

wm_terml[MEMORY_ELEMENT_SIZE+l];
wm_term2[MEMORY_ELEMENT_SIZE+1];

llret)

break,-

if (ret) {
/" <
while (chain) {
chain = chain->next;
free(temp);

i|||||

I .
I ( ).

I
| . 13. addToChah
v o i d addToChain( c h a r * e l e m e n t )
memoryElementType

*walker,

newElement;;

(memoryElementType *)malloc(s aeof(memoryElei

newElei

else {

strcpy( newElement->element, e ement );

if (chain) {
temp = chain
chain = chai:
free(temp);
}

if (chain == NULL) {

sntType) ) ;

} else {
w h i l e (walker->ne
w a l k e r - > n e x t = ne

jElei

} while (chain);
> 8.14.
searchWorkingMemory
c h e c k P a t t e r n
, ?.
. , addToChain. ( ? ). ,
,
? .
,
.
, ( ) . (,
b a t t e r y - l ) .
addToChain, , , { 8.13).
searchworkingMemory ( 8.14)

i n t searchWorkingMemory( c h a r * t e r m l , c h a r *term2 )

: wm_terml[MEMORY_ELEMENT_SIZE+l];
: wm_term2[MEMORY_ELEMENT_SIZE+1];
nil
if

(1)

(w o r k i t igMemory[c\ jrMem].ac tive)

/ * ;
s s c a n f (j o r k i n .gMem<[m] .element
win_term2);
WTin_terrri1.
i f (wm_term2[ strlen(wm_ter m2)-l] ==
wm_term2[st: rlenfwm.t erm2)-1] =

if ((!strncmp(terml, vmi_terml, s t r l e n ( t e r m l ) ) ) &&


(!strncmp(term2, wm_term2, strlen(term2)))) {

; |

B 3 3 H H H 1 1 I 1
break;

} else if (!strncmp(walker->element, "(disable", S)) {


ruleSet[rule].active - 0;
ret - 1;
} else if (lstrncmp(walker->element, "(print", 6)) {
ret = performPrintCommand( walker->element );

if (curMem == MAX_MEMORY_ELEMENTS) {
break;

} else if (!strncmp(walker->element, "(enable", 7)) {


ret = performEnableCommandl walker->element );
} else if (!strncrnp(walker->element, "(quit", 5)) {

ret;

extern int endRun;


, c h e c k P a t t e r n c h e c k R u l e ( 8.11).
, f i r e R u l e ,
, , , c h e c k P a t t e r n . ,
?,
.
, . ', , ( 8.15).
. 15. f ireRule

loryElementType walker = r u l e S e t [ r u l e ] . isequent;


ir newCons[MAX_MEMORY_ELEMENTS+1];
while (walker) {
if (!strncmp(walker->element,

et;
f i r e R u l e
, .
^'
I , .
( ), ;
| . ,
(, ( f a s t - c h a r g e ? ) ) ,
| ( a r g ) , , !
. 8.16.

| 8.16. constructEl eme


" ( a d d " , 4))

constructElemenM newCons, walker->element, a r g );


r e t = performAddCommand( newCons );

;onstruetElement( newCoi
ret - performDeleteCommc

endRun = 1;

ralker->element, a r g ] ;
) ;
lewCoi

void const rue tEleinent ( char *new, const char o l o , const cnar *arg )
{
/* */
ol<5++;
while ( ( * o l d != 0) && (*old != ' ? ' ) ) *new++ - *old++;

II

if (*old == 0) {

HIM
/*
s l o t = findEmptyMemSlotO ;

} else {

if (Slot < MAX_MEMORY_ELEMENTS)

/* arg */
while (*arg != 0) *new++ = *arg++;
if ( *(new-l) != " ) " ) *new++ - ) ;

workingMemory[slot].active = 1;
s t r c p y l workingMemory[slot].elem
} else {
assert(0);

r e t u r n 1;
c o n s t r u c t E l e m e n t () .
?, ?
. b a t t e r y - 1 ,
( f a s t - c h a r g e ?), ( f a s t - c h a r g e
batteryl).
, . , add, ( 8.17). add :

add ,
, ( ) :
( f indEmpt]
MemSlot, . 8.18) .
; , .
, r u l e F i r
8.18.
i n t findEmptyMemSlot( void )

(add (fast-charge ?))


, :
_(add

(fast-charge battery-2))

8.17.

r (i
if {i

0 ; i < MAX_MEMORY_ELEMENTS
rkingMemory[i].active) break

performAddCommandt char *mem )

nai
: MAX_MEMORY_ELEMENTS ; slot++) {

if (!strcmp( workingMemory[slot].element, mem )) {


/* - */
return 0;

d e l e t e ( 8.19).

. , (
; ). d e l e t e ]
:
(delete

(fast-charge ?})

8.19.
int performDeleteCommandl char 'mem )

ml[MEMORY_ELEMENT_SIZE+1];
m2[MEMORY_ELEMEKT_SIZE+1];


printf("%s

char wm_terml[MEMORY_ELEMENT_SIZE+l];
char wm_term2[MEM0RY_ELEMENT_SIZE+l];

for ( Slot = 0 ; s l o t

MAX_MEMORY_ELEMENTS

, string);

return I,;

slot++

[ s l o t ] .element, " (%,


if (!strncmp<terml, wm_terml, surlen(terml) ) &&
!strncmp(term2, wm_term2, sCrlen[term2))) {
workingMemory[slot].active = 0
bzero( workingMemoryfslot].elei n t , MEMORY.ELEMENT.SIZE );

enable ( 8.21).
:
(enable (timer N ))
Ns> , > -
.
.21.
int performEnableCommand( char element )
char *string;
int timer, expiration,void startTimerl int, int ) ,string - strstr( element, "timer" >;
sscanf ( string, "timer %d %d", &timer, &expiration ). ,.);

perf ormAddCommand, ruleFire.


p r i n t ( 8.20).
, . f ormPr intCommand 4" *". :
(print ("this is a t e s t . " ) )
8.20.
i n t performPrintCommand( char *element
char string[MAX_MEMORY_ELEMENTS+1];
i n t i=0, j=0;

, disable quit, f ireRul


' ( 8.15). d i s a b l e ,
) , a quit .
(disable (self))
(quit null)

processTimer
; ( 8.22),
, (
/ ). f i r e
; Timer ( 8.23).
' 8.22.

/* Find i n i t i a l */
while ( element[i] != *') i++;
/* Copy until we reach the i
while ( element[i] != ' " ' ) ;
string!j] = 0;

(i = 0 ; i < MAX_TIMERS ,-ing[j++] = elei

II


fireTimerl i );

, , .
( ) , , ( t i m e r - t r i g g e r e d X). ( f ormAddCommand) . ,
, .
8.23.

ait[MEMORY_ELEMENT_SI2E+1J;
: performAddCommand( char *m

ret = performAddCommand(

et;

e n a b l e . ,
, 8.24, .
8.24.

,
.

. , , ,
,
. ,
, (
. ).
!
;.' . , ,
8.25.
i 8.25.
(defrule stagel-check
[stage stagel)
(battery-temp low)
(add (check battery-temp))
(delete (stage stagel))
(add (stage stage2))
rule stage2-check
(stage stage2)
(battery-temp low)
(add (check battery-pressu.
(delete (stage stage2))

( s t a g e s t a g e X ) .
s- ,
I . , "
|' .
, . ;
; .
I',, i n i t
f - . (
^ 8.2) .


, ,
. , , <


>i )

Hi

, , . ,
, . ,

. , ,
, .
, .

,
,

. ,
, , . ,
, . ,
.
. ,
, .
, . ,
, .
. , , , , , , .

- , .
, .
,
.
( ZOOKEEPER),
, . , (, ), .

1. . . (Winston P. H. Artificial Intelligence,


3'' ed. Addison Wesley, 1993).
2. . . : (Forgy
. L. Rete: A Fast Algorithm for the Many Pattern/Many Object Pattern Match
Problem // Artificial Intelligence, 19:17-37, 1982).s

|||

9.
, , 1963 .
(Lotfi Zadeh), . . ,
, ( ). (Fuzzy logic) , . , ,
, 0,0 1,0 .

. 9.1. QoS
:
,
.
, * .
, * *
? (. 9.2).

, , ,
.


,
. QoS ( ), . ,
. , . . -
, -
, - ,
(. 9.1).
, ,
. :
,
.


. 9.2.


(Membership function) ( ) . QoS | (. 9.2).

e ^

. 9.2 ,
(). , 9.1:

,
(100-r

ate(x) >= 100

(9.1)

rate = rate + (mjow(rate) x pdelta) - (m_high(rate) x pdelta)


, 9.2:

m_Bigh(x) = {
0,

rateix) <= 100

(rate
l,

-ate(x) >= 120.

x) < 120

(9.2)


. 9.1 . ,
.
9.1.

mjow(x)

m_high(x)

1.0
0,75

0,0
0,0
0,0
0,0
0,0
0,25
0,5
0,75
1.0

0,0

.

? , .
, (, ). , ,

I , . , .
. , ?
, ' , .
^ 9.3:
(9.3)

r a t e - ,
( ). p d e l t a - , ,
. , .
, pde 11 a,
1 10. , .
r a t e 110,
? 9.3, :
rate - + (0 10) - (0,5 10) - 105.
1110, :
rate - 105 + (0 10) - (0,25 10) - 102,5.
, , 100, , .
, 9.3 :
rate - 80 + (1 ) - ( 0 10) = 90.
- , .


. , , - .
1 , , .
( ).

i||j

. 9.3.
, .

i
--*-- --*- -

t?

I
!
*
*
*
*
?!

0.5

is.

--- -
-
-200

-150

-150

-50

50

100

150

200

. 9.3.
,
. - , .
[+1, - 1 ] . [+8, -8] , , [+15, -15].
- , .
. .
. 9.4 ,
. 9.3.
[100, 100], ( [84,30]). (
45) . , , (
5 ).

. 9.4.

,
! . , -.
. 9.2.
9.2.

Truth(AORB)
Truth(A AND )
Truth(NOTA)

MIN{truth(A), truth(B))
MAX(truth(A), truth(B))
1,0 - truth(A)

.
:
if (m_warm(board_temperature) AND m_high(fan_speed) ) t h e n ...
, :



(Hedge)
. . - VERY
NOT__VERY.
. 9.4 9.5:
VERY(m_x) = m_x2

(9.4)

NOT_VERY(m_x) - m_x0-5

(9.5)

, . 9.2. 115 m_high 0,75. VERY (VERY (m_high ( r a t e ) ) , 0,5625


( , ).
119, m_high 0,95. VERY 0,903 ( ).


, . , ,
.


( ).
, (, ), . , . : .
, . .
, , - . . , , , . ,
, , , ,

111

. , , , ,
. , . , . .


, :
I . 1. : .
| :
if m_voltage__high ( v o l t a g e )
t h e n mode = t r i c k l e _ c h a r g e
if nutemperature_hot ( t e m p e r a t u r e }
if ( ( not (m__voltage_high ( v o l t a g e ) ) ) AND
( not(m_temperature_hot < t e m p e r a t u r e ) ) ) )
t h e n mode = f a s t _ c h a r g e
, , I- . .
.
^ , ;. , .
.

|:
. :
( | ) . 9.5 9.6.
f : , .
^ : , 1 . I - .


.
, ( , ).

^ __

, ,
. ,
,
. ,
.


: .
AND,
NOT, ( 9.1).
5
.

9.5.

10

15

20

25

30

9.1.
#d
e MAX( a,b]
#d ef in.e MIN{ a,b)

{ ( a>b)

t (a<b)

? a : b)
? a : b)

fuzzyType fuzzyAndt fuzzyType a, fuzzyType b )


return MAX{a,b);
fuzzyType fuzzyOrf fuzzyType a,

return MIN(a,b);

fuzzyType b ]

fuzzyType fuzzyNot( fuzzyType a )


{
return! 1.0 - a );
, . 9.

( 9.2).
,
..
. 9.6. :

'

^_ ^
alu

= (-lo);

if
({lo < 0) && (high < 0)) {
high = -(high - lo);
} else if (do < 0) && (high > 0)1 {
high += -lo;
} else if (do > 0) && (high > 0)1 {
high -= lo;
peak = (high / 2.0);
lo - 0.0;
if (value < peak) {
return! value / peak );
} else if (value > peak) {
return! (high-value) / peak };

, spikeProf ile,
(,
. 9.3). 1 hi, *
ie . hi/2.
, plateauProf i l e , ]
( - . 9.6
plateauProf i l e ]
, (,
. 9.6).
, /
.


,
. .
, ,
.
(<
9.3).
9.3.

float hi_plat, float hi )


float upslope;
float downslope;
value += (-lo) ,if (lo < 0.0) {
lo_plat += -lo; hi_plat += -lo;
hi
+= -lo; lo
=0;
} else {
lo_plat -= lo; hi_plat -= lo;
hi
-= lo; lo
= 0;
upslope = (1.0 / (lo_plat - lo));
downslope = (1.0 / (hi - hi_plat));
if (value < lo) return 0.0;
else if (value > hi) return 0.0;
'else if (value < lo_plat) return I(value-lo) * upslopfi);
return 0.0;

fuzzyType m_voltage_low( float voltage )


{
const float lo = 5.0;
const float lo_plat = 5 . 0 ;
const float hi_plat = 5.0;
const float hi = 10.0;
if (v ltage
ltage

iat
float
>at
>at
if (v ltage
if (vi ltage

lo)

lo = 5
lo_pla
hi_pla
hi = 2
lo)

[ 1.0,L 0.0;

- 10.0;
= 20.0;
[ 0.0;
l 0.0;

fuzzyT

y p e m_voltage_high( float voltage )


}
float
fl at
fl at
float

lo = 25.0,lo_plat = 30.0;
hi_pl at = 30.0;
h = 30.0,

fuzzyType m_voltage_medium( float voltage )


{
const float lo = 5.0;
const float lo_plat = 10.0;

ltage < lo) retu rn 0 0


It age > hi retu rn 1 0

const float hi = 25.0;


if (voltage < lo) return 0.0;
if (voltage > hi) return 0.0;

9.3 p l a t e a u P r o f i l e , . , .
. ,
p l a t e a u P r o f i l e .
[ l o , l o _ _ p l a t , h i _ p l a t , h i ] , .
, 9.3, . 9.5.
9.4 , .
9.
fuzzyType m_temp_cold( f l o a t temp )

return plateauProfile( voltage, lo, lo_plat, hi_plat, hi );

, 9.4, . 9.6.

, . c h a r g e i C o n t r o l ( 9.5) .
/1 9.5. ,
'oid chargeControl[)

{
const float lo - 15.0;
const float hi_plat = 15.0;
const float hi - 25.0;
if ( (
if (temp < lo)
if [temp > hi)

const
const
const
const

float
float
float
float

i 1.0;
i 0.0;

lo - 5.0;
lo_plat = 5 . 0 ;
hi_plat = 5.0;
hi - 10.0;

10)

= 0 ) {

ali
if (i
( m_voltage_high( voltage ) ) ) {
chargeMode = TRICKLE_CHARGE;
'timer = 0.0;
ChargeMode = TRICKLE_CHARGE;
*timer = 0.0;
} else if (normalize!
fuzzyAndf
fuzzyNotf m_voltage_high( voltage ) ),
fuzzyNot! m_temp_hot( temperature ) ) ) ) ) {
-hargeMode = FAST_CHARGE;
*tim.
= 0.0;

;||||

,

.


,
, ( 9.6).
9.6.
int main

. float timer;
. int simulate(void);

- -*- -*

extern float temperature;


extern i n t chargeMode;
for (i = 0 ; i < 3000 ; i++} {

. 9.7.

simulate();
chargeControlf

&timer );

timer += 1.0;
printf("%d, %f, %f, %d\n-, i,
voltage,
chargeMode
) ;
}
return 0;
, / , . , .
. 9.7. , . 50%

>. ,
.
, .

i , , .
, , .
, , .

^ . ,

j:
. , .


. - ,
. , , (, ) , .
, . ,
, . ,

, .

10.
| (Markov Model),
), , (Bigram Model).
, , , .
1 . .

.
( , ).
-, . ,
. ,
. , , .

(Markov Chain) , 1 , .
. 10.1 tomorrow (). .
tahmorrow 0,5, -rtuwmor 0,5.


1. Aptronix, Inc. (WhyUse Fuzzy Logic,
1996). http://www.aptmnix.com/fide/whyfuz2v.htm.
2. . . - (Brule J. F. Fuzzy
Systems - A Tutorial, 1985). http://www.austi nlinb.com /
Fuzzy /tutorialhtml.
3. . . (Zadeh L. A Fuzzy sets //
Information and Control, 8:338-53, 1965).
5. . Qantzen J. Tutorial to Fuzzy
Logic // Technical Report no 98-E 868. - University of Denmark, Department
of Automation, 1998).

. 10.1.
, . . . , , ,
.

___ ^

^_____

__

.__

. , .
, , , (.
. 10.2).

^^^^ ||||

. (Bigram),
I .
I , .
I , , .
I ( )
I ( ),
.
1 . 10.1, ,
I 100 .
| 10.1.

10000
1000000
10000

100 ,
.
. 10.2.

, 8 10 ,
2 - . , 80% , , 20%
. , , , . .

. .
, . . , (,
. 10.2).
(Hidden Markov Model - ), (Hidden
Markov Chain).


[ , , .
.
, , :
.


, - !
| (. 10.1).
,

!;
1 . ,
| , - tomorrow (
) today* (). tah, npi
tomorrow-, today. ]
I ; , today
I .
? , .
; , ]
; , , ,
.
.
, -

rjPJw

, . , (. 10.3).

What is a toad?
Where is the road?

G>0
:

What is a toad?
Where is the road?
What is the road?
Where is a toad?

. 10.4.


. 10.3. ,

, , .
,
. ,
. .




. ,
. , .
. 10.4 . - ().
*, the. , ( . 10.4).

, , . . .
.
;

, , , , . ,
.
. ,


, www.dmk.ru.


,
| , .

Hill

_ _ _

,___

.
, . -
, - , . , .
10.1 , .

/* */
srand(time(NULL));

10.1.

/+ ;
parseFilet filen<

define MAX_WORD_LEN 40
#define MAX_WORDS
1000
#define FIRST_WORD
#define MIDDLE_WORD
#define LAST_WORD

0
1
2

#define START_SYMBOL
#define END_SYMBOL

0
1

s t a t i c i n t curWord = 2;
char
int
int

wordVector[MAX_WORDS][MAX_WORD_LEN];
bigramArray[MAX_WORDS][MftX_WORDSj;
sumVector[MAX_WORDS];

40 (MAX_WORD_LEN), 1000 (MAX_WORDS). curWord wordVector


bigramArray. START_SYMBOL END_SYMBOL . ,
FIRST_WORD, MIDDLE_WORD LAST_WORD
( , ).
10.2.
: , ( p a r s e F i l e ) , , , ( b u i l d Sentence).
10.2.
int main( int argc, char *argv[] )
{
char filename[40];
' int debug = 0 ;
/* i
parseOptioi ( argv, argc, Sdebug, files

>(bigramArray,

|||

of (bigramArray) ) ,-

strcpy(wordVector[0], -<START>");
Strcpy(wordVector[1], "<EHD>");

if (debug) emitMatrixO ;
printf("unique = %d\n", curWord);
/* :
buildSentencet);

.
, ,
EX. ,
| | r d V e c t o r . , w o r d V e c t o r
, .
,
. , - .
, .
, - f ( , a -v
) ). ,
, ( 10.3).
10.3. parseOpt ions
)id pars eOpt ions ( char *argv [ ] , int argc, int *dbg, char *fname )
int opt, e r r o r = 1;
*dbg = 0,if (argc > 1) {
while ((opt = getoptfargc, argv, "vf:")] != -1) {
switch(opt)

*dbg = 1;

||_1

;
} e l s e if ( ( ( c h a r ) i n p == OxOd) || ( ( c h a r ) i n p == OxOa) ||
( ( c h a r ) i n p == ' )) {
if (index > 0) {
word[index++] = 0;
if (first) {
/* */
loadWordfword, FIRST_WORD);
index = 0;
first = 0;
} else {
/* */
loadWord(word, MIDDLE_WORD)
index = 0;

if (- .) {
printf("\nUsage is : \n\n-);
printf ("\t%s -f <filename> -v\n\n", argv[0]) ,printf("\t\t -f corpus filename\n\t\t -v verbose mode\n\n");
exit(0) ;
}

/* npei
word[index++] = 0;
loadWord(word, MIDDLE_WORD);
loadWordfword, LAST_WORD);
index = 0 ;
first = 1;

parseOptions getopt,
.
p a r s e F i l e ,
, ( 10.4).
10.4. parseFile

} else (

void parseFilei c h a r "filename )


{
FILE *fp;
i n t inp, index = 0 ;
Char WOrd[MAX_WORD_LEH+l] ;
int first = 1;

/* */
if (((char)inp 1= OxOa) && ((char)inp != ','))
word[index++] = (char)inp;

fp = fopen(filename, " r " ) ;


while (ifeof(fp) ) {
inp = fgetc(fp);
if (inp == EOF} {
if (index > 0) {
/* */
word[index++] - 0;
loadWordfword, LAST_WORD) ,-

}
parseFile
.
,
.

i wordVector bigramArray ( loadword).


JTO , ,
_ . ,
?
loadWord , , .

_ _ _ _ _ ..

__

,
, .
loadWord ( 10.5)
, .

imvector[lastlndex]++;

10.5. loadWord
void loadWord( char *word, int order )
int wordlndex;
static int lastIn.

= START_SYMBOL;

if (!strcmp(wordVector[wordlndex], word)) {
break;

if (curWord == MAX_WORDS) ( .
printf("\nToo may words, i:
exit (-!);

; MAX_WORDS\n\n");

/* -
strcpy(wordVector[curWord++],
word);

/* */
if (order == FIRST_WORD) {
bigramArray[START_SYMBOL][wordlndex]++;
sumVector[START_SYMBOL]++;
} else if (order == LAST_WORD) {
bigramArray[wordlndex][END_SYMBOL]++;
bigramArray[END_SYMBOL][wordlndex]++;
SumVector[END_SYMBOL]++;
} else {
/* ;
bigramArrayIlastIndex][wordlndex]++;

loadWord ,
( ).
wordVector. ,
wordVector
( curWord).
wordVector. ( , ), bigramArray. ,
START_SYMBOL ( ) te , wordlndex. , sumVector, .
, bigramArray , ,
! , LAST_SYMBOL .
(, ., , - . l a s t Index. . 10.5.
, .
, .
b u i l d S e n t e n c e bigramArray
sumVector ,
( 10.6).
10.6. buildSentence
i n t buildSentence( void )
{
- i n t word = START_SYMBOL;


8
^ s _

s, 1 |
STAKT_SYMBOL

>||

,
. , .
-buildSentence nextWord,
[ ( ) . 10.7.

10.7. nextWord

END_SYMBOL

i n t nextWord( int word ]

What

1
1
1
1

What is a toad?

w h i l e {nex
/*
nextWord

rd ! = word) {

exttord % curW

*/
bigramArray [word] [nextWord] ,-

. 70.5. bigramArray -
/* , )
while (word 1= END_SYMBOL) {
rordVector[word]>;
/* :
word = nextWord(word);
/* !
max += getRand(12) + 1,-

i
i f {sum :

ira] {
extWord;

}
/* i
nextword++;
}

= 100) b r e a k ;

/* ,
printf("%c.\n\n", 8);

buildSentence bigramArray , . ,

1
nextWord . - s u m V e c t o r ( , | > . ( l i m )
I , . |.' ,
. $ , .

EEQHMUIIIEP

1 1

<j

10.11.

10.8. emitMatrix

iot@plato bigrairi] ./bigram -f combo


] chaos and beasts and hostile short
Lter strayed.

void emitMatrix( void J


{
i n t x, y;
printf C\n") ;
for (x = 0 ; x < curWord ; x++) {
printf("%20s : ", wordVector[x]);
for ( = 0 ; < curWord ; y++) {
printf("%d ", bigramArray [x] [y] ] ,}
printff" : %d\n', sumVector[x]);

10.9.
Imagination is shipwrecked by language and other symbolic
devices.

10.9 .
,
( 10.10).
10.10.
^
[root@plato bi.Qrain] . /bigrairi f absurdman
It is to speak only truth that is the breath of future actions.
[rootplat bigrajn] . /bic^ram ~f absux"drnan

i the woods the

,
, . : ?
,
.
,
.

,
-

,
.

. 13
377 (. 10.9).

, ,
: ( 10.11). - ), - *- .

, .
, 10.8 , e m i t Matrix, bigramArray sumVector.

, ,
) .
- 1 . 1 , . , .
, , . , .


1. . . : (Balid P.
and Brunak S. Bioinformatics: The Machine Learning Approach. - Cambridge,
Mass.: MIT Press, 1998).
2. . .
(Baker J. J. In R. Reddy (ed.) Stochastic Modeling for Automatic Speech
Understanding// Speech Recognition: Academic Press, pp. 521-42,1975).
' 3. . . 4190.515: ( ) (Zheng .
- Course 4190:515: Bioinformatics (Machine Learning) // Seoul National

__

University School of Computer Science and Engineering, 2001).


http://bi.snu.ac.kr/Courses/p-ai01 /g-aiOl .html.
4. . : n-gram (Henke J. Statistical Inference; n-gram Models over Sparse Data, TDM
Seminar, 1999). http://www-sims.berkeley.edu/courses/
is29fia-4/f99 /Lectures /her.ke-ch6.DDt.
5. - . (Shannon . . A mathematical theory of communication // Bel! System Technical Journal 27 (July and
October), pp. 379-423 and 623-56, 1948).
6. . .
(Shannon . . Prediction and Entropy of Printed English // Bell System Technical Journal 30:50-64, 1951).

1 1 .
,

( (Agent).
, ,
. , , .
Internet-.


(Alan Kay), , ,
. , ! , . , Internet
| .
; (Intelligent agent), 1 . , , - . ,
> , (, , ). , -
- ,
. ,

: .
. , , ;[ .


i , 1 . 11.1
; < 1 .

^'

11.1.

HI
:

i
( )

, , (Autonomy). ,
.
, .
,
. , . .
(Adaptivity), .
.
, ,
.
(Communicative). ,
.
, . ,
, Web-, HTTP, ( ). .
(Collaborative),
. , , , , , . ,
.
, .
(Personality).
. ,
, ,

[ . , -
| ,
| . , , ,
| .
, (Mobility), t . I . ,
I .
1 , ,
| , .
I , I , ,
| . ,
, , .
. . , ,
, , .

, (. 11.1).

. 11.1.

, ^
, (Franklin and Graesser).
, .
,
, ,
. Internet. , ,
.
, ,
.
, ,
.
, ,
, ( , ).
,
. ,
Internet .
. , , .

, . .
, (Ananova) Ananova Ltd.
, , . , .
.
,
. :
,
.

- .
, ,
, .
,
.

. , Aglet IBM,
Internet (. *).



, , , .
(. 11.2).

. 11.2.

5
, .
,
,

.
8 , , . ,
. , .
(, , 3) .
,
- ( ).

HIIf

09'

, ,
. , ( 9) ( 2).


, . , Internet ,
. - ,
( ,
).
Web-
Web- .
HTTP-, HTTP-,
NNTP (. 11.3).

:||

1 ( ) .
| , ,
Web-,
& .
: .
, , 1 ,
| .
Web-
Web- .
[ : ( ) .
,
. HTTP. Web-, Web-.
Web- ,

HTTP

HTTP/NNTP

. 11.3. Web-

Web- , Internet .
( ). Web-

Web-. , (. . 11.4).
10 . . , ( ), ,
, .
, HTML Web, HTTP- (. 11.5).
, (. 11.6).
, , :. Web-; ; .
, Web-,
[. config.html (. 11.7).
Web-
, . 11.4. Internet

2 WehAgenT - MrcruSulI inEurnel I xp[--

Web-

Web Agent Results


com'
-63"

31 grt 2 01:45:01
31 ott 2002 :: 18

"

je

nars sample ftfum

, J7 sep 2002 14:00:05 ginl

re
use satelfag

.re_ mars
bara

from oftcr

, IT jpp 2002 23:5~:H-0400


-1
'succf ssfui launch tor biij>a?jt f d satclblt bald by alcatel ?pacg
, 19 lep 2002 12:24:5^ gmt
=. imagery
brcaklhrou^iin eatrbqi^kc research ^bu. 19 sep 2002 13:35:40-0400 j

HTML

assure la mise a

loral and act ialcdfle

ofaostar-^ssiiMs

\sutL,12 *rp l&il ll:il:16


?WIIL,2$ sepQ2 20:53:30

. / /.5. Web-, Web-

Microsoft FfltCTfn.-E E*|)lurer

Subject : announces microgravity combustion science research


grants

Sender : baalke@soganii . jpl. nasa .gov (ron baa Ik)


Group . sci.space.news
Msg Date : 23 oct 2002 16,11,48 gmt

Dwayne Brown
Headquarters, Washington
October 2, 2002
(:

202^358-1726)

RELEASE; 0 2 - 2 0 5
H?iSA ATOJOUNCES MICROGFAVITY COMBUSTION SCIENCE RESEARCH GRANTS
selected 22 researchers to reeieve grants totaling Approximately SB. million
to conduct fflicrogravity combustiou ground-baeed research. Nine grants era to continue
research currently funded by NASA and 13 represent new research.
research offers investigators the opportunity to take advantage of a lo-gravity -

. 11.4. Web-
. 11.6*

Ill

^"

- - - :Configuration

Fetd nntpT/'ydlow.gcfks.org

| | | | | |
m o n i t o r S i t e (. 11) ,
, ( ).
11,1, HTTP

typedef struct {
char url[MAX_URL_SIZE] ;
char urlName[MAX_SEARCH_ITEM_SIZE+13;
int length;
int changed;
int shown;
} monitorEntryType,- int monitorSite( int sitelndex )

struct sockaddr_in servaddr;


char buffer[MAX_BUFFR+1] ;
char fqdn[80] ,. / J. 7. Internet
. , .
. , HTTP .
Web-
Web- N N T P HTTP. HTTP-,
, .
HTTP
HTTP - , , Web- .
HTTP G E T .
. , c o n t e n t - l e n g t h ,
( ).
, . , , ,
.

extern monitorEntryType monitors!];


/* */
sock = socket(AF_INET, SOCK_STREAM, 0 ) ;
1, fqdn );
'addr] };
'addr.sin_family = AF_INET;
'addr.sin_port = htons< 80 );
/* */
servaddr.sin_addr.s_addr = inet_addr( fqdn );
/* IP-,
*

> '
DHS
1

(struct hostent *)gethostbyname( fqdn );


if { hptr == NULL ) {
close(sock);
in_addr **addrs,

if!

addrs = (struct in_addr **)hptr->h_addr_list;


memcpy( Sservaddr.sin_addr, *addrs, sizeof(struct in__addr) );

/* HTTP- */
result = connect(sock,

if (result == 0) !
/* GET */
strcpylbuffer, "GET / HTTP/1.0\n\n") ,-

len = grabResponsef sock, buffer );


cur = strstr(buffer, "Content-Length:"),if (cur 1= NULL) {
int curLen;

moni torSi te , . socket.


URL prune,
http://www.mjtones.eom/u
www.mtjones.com ( , .
,
www.dmk.ru).

, , , IP-.
IP-, '. , IP-
. i n e t _ a d d r
> IP- IP-. :, gethostbyname IP- DNS:.
IP- ( s e r v a d d r ) , connect. ,
. HTTP-
3> ( 80), , HTTP. GET , . ( g r a b R e s p o n s e , 11.2),
, C o n t e n t - l e n g t h . , ,
!~ .

iitors[siteindex].shoi
71.2. HTTP-
int grabResponse ( int sock, char *buf)
len,

bufldx;

if (buf == MULL) return -1;


len = bufldx = state = stop = 0;
close(sock|;

while (istop) {

return(ret|;
m o n i t o r E n t r y T y p e (URL)
urlName, Web-, . l e n g t h , , .

jck, &buf[bufldx],

(MAX_BUFFER-bufIdx)

. * /

- | |

,
215 l i s t of
control 2 3
Lte
Lte
Lte
te

else if
break;
else state = 0;

== 2) && (nei
= = 2 ) && (net
== 3) && (net
== 4) && (new

i] == OxOd
i ] == " . "
i] == OxOd
= OxOa) ) { stop = 1;

: my.group 10
: new.group 6
group my.group
. 211 8 3 10 my.group
article 3

bufldx +=, len;


Date: S a t , 05 Jan 2002 00:47:27 -0700
From: "M. Tim J o n e s " <mt j @rnt jones . com>
X-Mailer: Mozilla 4.74 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: my.group
S u b j e c t : t h i s is my post

}
bufldx -= 3;
news->msg[bufldx] = 0;
return bufldx;
HTTP- CR/LF.
( 11.2) ,
. , 0.
HTTP-.
HTTP. ,
. ,
.

Content-Transfer-Encoding: 7 b i t
NNTP-Posting-Host: s a r t r e . m t j o n e s . c <
X-Trace: plaCo.mtjones.com 101032871
m 2002' 07:52:44 -0700)
Lines: 6
Path: plato.mtjones.com
Xref: p l a t o . m t j o n e s . c o m my.group:3

NTTP-
NTTP .
( n t t p C o n n e c t ) ,
( n t t p S e t G r o u p ) , ( n t t p P e e k ) ,
( n t t p R e t r i e v e ) , ( n t t p P a r s e ) ,
( n t t p S k i p ) ( n t t p Close).
NTTP ,
ASCII-. Telnet
119 NTTP- ( 11.3) . , , .
11.3. NTTP-
S: 201 p l a
: l i s t

1 5 . 5 d l , SO, posl

:: date
3: 111 20"020112122419
:: quit
3: 205 closing connection goodbye!

3 11.3 , NTTP- Telnet-. , . . ,


- . (.
d a t e ) .
,
*. , NNTP,
SMTP, . (. l i s t a r t i c l e ) .

JTO^ocHOBaHHoe ^^

, NNTP, , .
NNTP news_t,
( 11.4).
11.4.

s_c

typedef struct {
char
isg;

struct in_addr **addrs;


raemcpyl &servaddr.sin_addr, *addrs, sizeof(struct in_addr) |;
}
result = connect! sock,

i n t msgld;
char subject[MAX_LG_STRING+l];
char sender[MAX_SM_STRING+1];
char msgDate[MAX_SM_STRING+l];
. char * b o d y S t a r t ;
} news_t;
n e w s _ t (msg), (msgLen) (msgld). ,
( s u b j e c t ) , ( s e n d e r ) (msgDate). ,
b o d y S t a r t .
NNTP n n t p C o n n e c t ( 11.5). NNTP-,
(IP- ).
11.5. nntpConnect . API

i f (inntpServer) return - 1 ;
sock = socket! AF_INET, SOCK_STREAM, 0 );

:ervaddr.sin_port

) else {

'_INET;
LS( 119 );

;ervaddr.sin_addr.s_addr = inet_addr( nntpserver I.


.f ( servaddr.sin_addr.s_addr == Oxffffffff ) {
struct hostent *hptr =
(struct hostent *)gethostbyname( nntpSer'
if ( hptr == NULL ) {

(struct sockaddr *)&servaddr, sizeof(servaddr] ];


if ( result >= 0 ) {
buffer[] = 0 ;
result = dialog( sock, buffer, -201', 3 );
if (result < 0) nntpDisconnect 0 ,-

return ( result );
n n t p C o n n e c t , ( n n t p s e r v e r ) . IP- ,
(. moni| o r S i t e ) .
: o n n e c t . NNTP (j> ID), ( d i a l o g ) .
: NNTP- 201, (. 11.3). , , NNTP
ft (-1).
d i a l o g , NNTP-cep1, ( 11.6).
, , ,
. , TCP . ,
0 , ,
:. , [ .
11.6. NNTP-

if ((sd == -1) II ('buffer)) return -1;


if (strlen(buffer) > 0) {
len - strlen( buffer );
if ( writef sd, buffer, len ) != len ) return -1;

if (resp != {
ret = read( sd, buffer, MAX_LINE ) ;
if (ret >= 0) {
buffer[ret] - 0;

if (result == 0) {
sscanf( buffer, "211 %d %d %d ',
fcnumMessages, SfirstMessage, fclastMesi
if (lastRead == -1) {
curMessage = firstMessage;
} else {
curMessage = lastRead+1;
numMessages = lastMessage - lastRead;

} else {

i group to %s\n", group);

. -1;

og( sock, buffer, -211", 3 ] ;

l 0;
,
buf f er, , (
s t r l e n ) . ,
w r i t e . , . ,
. ,
(0),
(-1).
. nntpSetGroup.
(, c o m p . a i . a l i f e )
.
-1 l a s t R e a d . , .
, NNTP , ( 11.7).
11.7. nntpSetGroup

NNTP . 211 ( ) : ,
.
. , , . [; nntpPeek n n t p R e t r i e v e .
n n t p P e e k ( 11.8),
1' n t t p R e t r i e v e (
)).
71.8. nntpPeek
. nntpPeek ( news_t "news, int totalLen )
nt result = - 1 , i, len=0, stop, state, buf!dx=Q;
-s)

(sock =

i n t numMessages = -1;
/* ID (

-1)) retir

-1;

11;

result - dialog! sock, buffer, "21", 3 ) ;


if (result < 0) return -3;
/* +OK (
* CRLF)
*/
len = strlent buffer );
for ( i = 0 ,- i < len-1 ; i++ ) {
if ( (buffer[i] == OxOd) && (buffer[i+1] == OxOa) ) {
len -= i-2;
memmove( news->msg, Sbuffer[i+2J, len );
bufldx = len;
break;

| | |
n n t p P e e k ,
i h e a d NNTP. NNTP-
1221, , . (news - >mag) ,
NNTP-. ,
, ( .
). ( news->msg)
[ (. n n t p P a r s e ) .
n n t p R e t r i e v e n n t p P e e k , , ( 11.9).
11.9. nntpRetr. -eAPI

:sult = - 1 , i, len=0, stop, state, bufIdx=0;

while (!stop)
if

(bufldx+len :

if ((curMessage == -1 II (curMessage > lastMessage))

alLen - 80) break;

/* ID
news->msgld = curMessage;

( i = bufldx ; i < bufldx+len ; i++

lse

if (

( s t a t e == 0
state == 1
state == 2
state == 2

lse

if (

state == 4)

f
lse
lse

(
if (
if (

&&
&&

ss

( n e ws->msg[i
( n e ws->msg[i
( n e ws->msg[i
( n e ws->msg[i
(nev s->msa(il

top = 1; break; }

== OxOd}
== OxOa)
== OxOd)
==
".")
== OxOa)

) state = 1
) state = 2
) state = 1
) state = 3

or { i = 0 ; i < len-1 ; i++ I {


if ( [buffer[i] == OxOd) S& (buffer[i+l] == OxOa!

bufldx += len;

bufldx -= 3;
news->msg[bufldx] = 0;
news->msgLen = bufldx;

state = stop = 0;
while (Istopi f
if (bufldx+len > totalLen - 80) break;
/* */

'

buf Idx ; i < bufldx+len ; i++


state == 0) && (news- >msg[i]
1) && (news- >msg[i]
state == 2) && (news- >msg[i]

)
== 0xOd)
== 0x0a|
== 0xOd)

sta te = 1
sta te = 2
sta te = 1

state == 3) && (news- >msg[i] == 0xOd)


state = 4
tate *= 4) && (news-;msgti] == OxOai ) (

op = 1; break; )
tate = Or

bufldx += (i-bufldx);

, curMessage NNTP-! nntpSetGroup.


( ) NNTP-,
news_t ( 11.4).
[ n n t p P a r s e ( 11.11), ,
I . , (
NNTP), bodyStart.
11.11. nntpParse

if ('stop) {
len = read( sock, &news->rasg[bufldx], (totalLen-bufIdx)
if ( (len <= 0) II (bufldx+len > totalLen) ) {
>ak;

if (!news) return - 1 ;

if (result < 0) return - 1 ;


result - parseEntry( news, "Date:", news->msgDate
if (result < 0) return - 2 ;

news->msg[bufldx] = 0;
news->msgLen = bufldx;

if (result < 0) return - 3 ;


fixAddress( news->sender ];

return bufldx;

if (flags == FULL_PARSE) {
r e s u l t = findBodyl news );

}
n n t p R e t r i e v e a r t i c l e NNTP, . , nntpPeek head, . NNTP , .
.
nntpPeek n n t p R e t r i e v e ,
, . nntpPeek n n t p R e t r i e v e . : nntpPeek , , . ,
nntpSkip, ( 11.10).
11.10. nntpSkip API
void nntpSkip( void )

sult;
, . ,
[ HEADER_PARSE. ( ) FULL_PARSE.
nntpParse parseEntry findBody. ,
,
rmmn.dmk.ru.
p a r s e E n t r y , . f i n d B o d y (
[ ).

, ^
NNTP, nntpD is c o n n e c t , NNTP- ( 11.12.).
11.12. nntpDisconnect API

if (sock
close(soc
sock = cu

, NNTP, , .
Web- NNTP-
, .


Web- . (. 11.13.).
11.13. Internet
Sample config file
ittp://w
,ttp://w tf.wnd.com/;WorldNetDaily
[feeds]
nntp://yellow.geeks.org
[groups]
.robotics.misc;camera;68HC11
sci.space.moderated;mars;gemini
,
, . ( [ m o n i t o r ] ) Web- . Web-
, http://. , (' ).
Web- , ,
.( [ f e e d s ] ) .

i | | | | | H ^

;. , (
nntp://, NNTP).
I , . ( ) .

I ( [ g r o u p s ] ) . | , . , ^
I , . Internet , !
I . ,
I , , .
. moni| t o r E n t r y T y p e , Web- ( 11.1)
I 11.14 f eedEntryType,
| , .
^ 11.4. f eedEntryType groupEntryType
#define MAX_URL_SIZE
#define MAX_SEARCH_IJEM_SIZE
#define MAX_SEARCH_STRINGS
#define MAX_GROUPS

80
40
10

20

typedef struct {
int active,char groupName[MAX_URL_SIZE+l];
int
lastMessageRead;
char searchString[MAX_SEARCH_STRINGS][MAX_SEARCH_ITEM_SIZE+1];
int
numSearchStrings;
} groupEntryType,' typedef s t r u c t {
Char
url[MAX_URL_SIZE];
groupEntryType groups[MAX_GROUPS];
} feedEntryType;

f eedEntryType (
I [ f e e d s ] ) ,
I (
:oups ]). , !
L- .
5 .

; parseConf i g F i l e . ,
( 11.15).

Ill

^'

11.15.

cur = parseURLorGroup( line,


feed.groups[curGroup].groupName );

int parseConfigFile{ char *filenaroe |


{

FILE *fp;
char line[MAX_LINE+l],
int parse, i;
bzerol &feed, sizeof(fe
fp = fopen(filename, " r " ) ;

i = 0;
while <*cur) {
cur - parseString(
cur, feed.groups[curGroup].searchString[i] );
if (strlen(feed.groups[curGroup].searchStringfi]II i++;
if (i == MAX_SSARCH_STRINGS) break,}
feed.groups[curGroup].numSearchStrings = i;
feed.groups[curGroup].active = 1;

if (fp = = NULL) return -1;


while! !feof(fp] ) {
fgets( line, MAX_LINE, fp )

if
(line[0] == #") continue;
else if dine[0] == OxOa) continue;

readGroupSCatus () ,return 0;

if
{istrncmpdine, " [monitor] ",' 9)) {
parse = MONITOR_PARSE;
) else if (! strncmpUine, "[feeds]", 7)) {
parse = FEEDS_PARSE;
} else if (!strncmp(line, -[groups]", 8)) {
parse = GROUPS_PARSE;
if (parse == MONITOR_PARSE) (
if (istrncmpdine, "http://", 7)) {
cur = parseURLorGroup( line, monitors[curM
monitors [curMonitor] .active = 1,curMonitor++;
} else if (parse == FEEDS_PARSE) {
if ( ! strncmpUine, "nntp://" , 7) ) f
cur = parseURLorGroup( line, feed.url I;
} else return -1;
} else if (parse == GROUPS_PARSEI {

. . # ( - ), .
| .
, , ( ,
> ). , p a r s e
, , .
, ( p a r s e ) .
HTTP. ,
seURLorGroup . p a r s e : i n g Web-, .
11.16. , , [ ( Web- )
Ji c u r M o n i t o r .
,
NNTP-. parseUELorGroup

,
u r l feed.
.
Web- , , . 10 ( 11.14).
, . n u m S e a r c h S t r i n g s .
11.16. parseURLorGroup parseString

/* !
w h i l e ( (*lii

[ ' ' () */
') && ( * l i n e 1= ' ; '

(line != )) {

if {i == MAX_URL_SIZE-1) br<

parseURLorGroup Web-
. ,
I ,
| - (, ). , -, u r l , . ,
t ,
I .
p a r s e s t r i n g parseURLorGroup.
. - . .
JT . >-, , p a r s e S t r i n g .
( 11.15) ,
) ( ).
r e a d G r o u p S t a t u s ( 11.17),
-
) .
11.17. adGroupStatus

return!

line );

-oid readGroupStatus( void )


FILE *fp;
int
i, curMsg;
char line[8O3;

i n t j=0;
if ( " l i n e != ;) {

for (i = 0 ; i < MAX_MONITORS ; i++l


feed.groups[i].lastMessageRead = - 1 ;
}
fp = fopen(GRPSTS_FILE, " r " ) ;
while (!feof(fp))
fscanft -fp,

while ( ( * l i n e != ' ,- ') && (*line 1= OxOa) ) {


if (j == MAX_SEARCH_ITEM_SIZE-1| break;
s t r i n g ! j ] - 0;
while ( ( * l i n e ! = ';) && (*line != 0)) linen
n( l i .

"%s : %d\n", l i n e , &curMsg );

for < i = 0 ; i < MAX_MOHITORS ; i++) {


if

(feed.groups[i].active)
if

(!strcmp(feed.groups[i]-,
feed.groups[i].lastMessageRead =

line))

curMsg;

Hill;

||1

for (i = 0 ; i < MAX_GROUPS ,- i + + ) {


if ( feed.groUps[i].active ) {
checkGroup( i );

r e a d G r o u p S t a t u s ,
(
). , , ( n n t p S e t G r o u p ) . 11.18.
11.18.
.robotic; misc : 96000
sci.space.hi; ory : 135501
( g r o u p . s t s ) . , :,
.
l a s t M e s s a g e Read feed. , .
, , (
). , lastMessageRead
(curMsg), . , , .
.
: .

, ,
checkNewsSources ( 11.19). feed checkGroup .
11.19. checkNewsSources
v o i d checkNewsSources( v o i d )

checkGroup , [ , (. 11.20).
5 11.20. checkGroup
<oid checkGroup( i n t group )
i n t r e s u l t , count, index = 0;
Char fqdn[80];
news.msg = (char *|malloc(MAX_NEWS_MSG+1);
bzerol news.msg, MAX_NEWS_MSG+1 );
news.msgLen = MAX_NEWS_MSG ,prune( f e e d . u r l ,

fqdn );

/* */
count = nntpConnect( fqdn ) ,if (count == 0) {
I * */
count = nntpSetGroup( feed.groups[group].groupName,
feed.groups[group].lastMessageRead );
index = 0;
if (count > 100| count = 100;
while (count > 0) {
result = nntpPeekt &news, MAX_NEWS_MSG );
if (result > 0) {

. feedEntryType feed;

H i l l

^ ^ '

if (result == 0) {
testNewsIteml group, &news );
}

nntpSkip();

:||111

IBS

I n n t p P e e k n n t p P a r s e , t e s t N e w s l t e m , | , .
l a s t M e s s a g e R e a d
I , .
I-, n n t p P e e k n n t p S k i p , (news. msg) NNTP- n n t p D i s c o n n e c t .

11.21.
11.21. testNewsltem
void testNewsltem( int group, news_t *news )

nntpDisconnect();
return;
c h e c k G r o u p NNTP-
p r u n e ,
(nntp://) (/) , . . NNTP- , ,
( , ). 64 msg news . msgLen, NNTP-
.
n n t p C o n n e c t NNTP-cep. , , . ,
. , .
, ( 200).
,
. n n t p P e e k ,
, .
( ) n n t p P a r s e .

int i, count-0;
char *cur;
if (feed.groups[group].numSearchStrings > 0) {
for ( i = 0 ; i < feed.groups[group].numSearchStrings ; i++ ) {
cur = s t r s t r ( news->subject,
feed.groups[group].searchString[i]

if (count)

];

insertNewsit'

| .

Ill' '

? flLIIPJL

, , . s t r s t r ,
. s t r s t r .
NULL, , .
c o u n t , , . ( , ). c o u n t (
), .
- , . e l e m e n t T y p e 11.22.
,
.
11.22. ele

tType,


newElement->group = group;
newElement->rank = count,newElement->msgId = news->msgld;
iubject, MAX_LG_STRING );
isgDate, MAX_SM_STRING ) ,-

xt =

elementType *)NULL;

while (walker) (
if (walker->next == (TOLL) {
walker->next - newElement;
break;

/* Otherwise, i n s e r t in rank o r d e r (descending)

*/

->next = walker->next;
xt = newElement;

group;
rank;
msgld;
subject[MAX_LG_STRING+1];
:har msgDate[MAX_SM_STRING+l];
link[MAX_SM_STRING+l];
} elementType;
; i n s e r t N e w s I t e m ( 11.23).
11.23. insi -Wei-

sJta

// Define the head


ElementType head;
:ntType *walker = &he<
ntType *newElement;
ltType

*)malloc(s

of(elementType)) ;


( e l e m e n t T y p e ) . e l e m e n t T y p e . ,
, g r o u p , r a n k ( ) , ,
. msglD ( ),
s u b j e c t msgDate.
shown ,
. , .
, ( ,
, ).
shown . ,
.

,
l i n k ,
.
HTML-. HTTP- ,
, , . , 7, 20999, a r t 7 _ 2 0 9 9 9 .
, .
, n e x t .
NULL ( ), , .
, e l e m e n t T y p e , , . , . , .
w a l k e r . , (. 11.8).


). , n e x t ,
, .
, , , ( ) ,
. , , . 1 .

Web- HTTP-,
. HTTP-, , ,
| .
HTTP- i n i t H t t p | j e r v e r . ,
- , ( 11.24).
11.24. initHttpServer

group

nt initHttpServer( void )

rank
msgld

int on=l, r e t ;
if (listenfd ' = -1) closet l i s t e n f d );
l i s t e n f d = socket! AF_INET, SOCK_STREAM, 0 );

shown
'next
. 11.8-
11.23 ,
, . ( ) - .
, , - . ( ). .

. , , (

/* */
r e t = setsockoptl listenfd, SOL_SOCKET,
SO_REUSEADDR, &on, sizeof(on) );
if (ret < 0) return - 1 ;

*/

izero( (void *)&servaddr, siaeof(servaddr) );


;ervaddr.sin_family = AF_INET;
;ervaddr.sin_addr.s_addr = htonl( INADDR_ANY I;
;ervaddr.sin_port = htons( 8080 );
/* servaddr */
ret = bind( listenfd,
(struct sockaddr *)&servaddr, sizeof(servaddr) );
if (ret < 01 return -1;

HMIII

^ ^ '

accept!

n(listenfd, 1] ,-

i|g|

listenfd,
ickaddr *)&cliaddr, u c l i l e n );

return 0;
}
i n i t H t t p S e r v e r , . , ,
. , , .
( 11.24) SCL.REUSEADDR, 8080. ,
, ( - ). 8080
( INADDRY_ANY). b i n d
l i s t e n , .
( , Web- ..), , HTTP-
. , - .
s e l e c t , ( 11.25).

if (connfd > 0) {
handleConnection( connfd );
Closet connfd );


litHttpServerf);

0) {
/* (
initHttpSe:

! ]

11.25. checkHttpServer
void checkHttpServer( void ]
{
fd_set rfds;

( 11.24), l i s t e n f d
HTTP-. s e l e c t ,
.
,
: ,
. Web- . :
c h e c k H t t p S e r v e r , ,
. s e l e c t
'. , ^
' .

. clilei
ickaddr.
FD_ZERO( &rf ds |;
FD_SET( l i s t e n f d , urfds );

if (ret > 0) {
if

(FD_lSSET(listenfd, Srfds)!
clilen = sizeof(cliaddr);

s e l e c t r f d s ,
I .
, l i s t e n f d , r f d ;
|, FD_SET. t i m e v a l
| , . *
; s e l e c t . , ( !
'i ),

Hill

, .
s e l e c t . , , -
HTTP-, i n i t H t t p S e r v e r .
, , ,
( ).
. , , . F D _ I S S E T ,
( l i s t e n f d, ). FD_ISSET , l i s t e n f d, a c c e p t handleConnect ion
. ',
i n i t H t t p S e r v e r .
handleConnect i o n HTTP-.
HTTP-, ,
. ,
HTTP- ( 11.26).
11.26. handleConnection
void handleConnection( int connfd )

cha

^' ^

buffer[MAX_BUFFER+l];
filename[80+l];

/* HTTP- */
max - 0; loop = 1;
while (loop) {

if <(buffer[max-4] == OxOd) && (buffer[max-3] == OxOa) &&


(buffertmax-2] == OxOd) && (buffer[max-1] == OxOa)]
loop = 0;
}
/* HTTP- */
if (Istrncmp(buffer, -GET", 3)) {

if (Istrncmp(filename, "/index.html", 11))


emitNewst connfd );
else if (Istrncmp(filename, "/config.html", 12))
emitConfigL( connfd ) ;
else if (istrncmp(filename, "/art", 3))
else
} else if (!strncmp(buffer, "POST", 4)) {

/* POST :
* . j
* /
if (istrncmp(filename, "/clear", 6)) {
clearEntriesO ;
emitHTTPResponseHeader( connfd );
"refresh page.</Hl><P>\n\n");
writelconnfd, buffer, strlen (buf fer) ),} else (

} else {
strcpy(buffer, "HTTP/1.1 501 Not Implemented\n\n";
write(connfd, buffer, strlen(buffer));

HTTP- ipoc. . ,
) , -
HTTP. , , .
KGET HTTP-; , . POST , ,

EE3HHHHM

__||

( CGI-: CGI
HTTP- ', ). , POST, , , .
GET , .
/ i n d e s t h t m l , Web- (. 11.5).
, emitNews. / c o n f i g . h t m l ( ) - . , 11.7.
/ a r t , , (. 11.6).
emitNews ,
. e m i t A r t i c l e . , HTTP- ,
HTTP- ( 404, ).
POST HTTP-
. / c l e a r , ,
( ). c l e a r E n t r i e s , emitHTTPResponseHeader
HTTP-. ,
( )
(Back) . , , . .
h a n d l e C o r m e c t i o n . HTTP- GET
POST, , ,
.
, h a n d l e C o n n e c t i o n . HTTP- g e t F i l e n a m e ( 11.27). ,
HTTP- .
, /,
g e t F i l e N a m e / i n d e x . h t m l .
11.27. getFileNamt?

int i = s t a r t , j=Or
/*
while (inbuf[i] == ' ' I i+
for ( ; i < strlen(inbuf)

if (inbuf[i] ==

') {

out[j] - 0;
break;
}
out[j++] - i n b u f [ i ] ;

, emitHTTPResponseHeader, 1 HTTP- ( 11.28). , [ , ,


HTML- ( C o n t e n t - t y p e ) .
1 11.28. emi tHTTPResponseHeader
lid emitHTTPResponseHeader( int connfd )
char line[8O3;
strcpy( l i n e ,

"HTTP/1.1 200 OK\n" };

strcpyl l i n e , "Server: tinyHttp\n" );


write{.connfd, line, strlen(line) );

write( connfd,

line,

strlen(line)

);

strcpyf l i n e , "Content-Type: texc/html\n\n"


write! connfd, line, strlen(line) );

);


jJTTP-. emitHTTPResponseHeader,
.
, h a n d l e C o n n e c t i o n , - c l e a r i i t r i e s ( 11.29). ,
. , , ; , .
, , 1 .
(Mark Read) ,
.

Ill

_ ^

|||

c l e a r E n t r i e s shown Web-cav
, . Web-
| , , . ;:
; !
. , c l e a r E n t r i e s
e m i t G r o u p S t a t u s ,

( 11.30).

11.29. clearEntries
{
elementType 'walker - Shead;
elementType *temp;
int i;
extern monitorEntryType monitors[];
/* ( ,

11.30. emitGroupStatus
void emitGroupStatus( void ')
{
FILE *fp;

*/
while (walker->next) f
if (walker->next->shown) {

fp = fopen(GRPSTS_FILE, "w");

walker->next = walker->next->next;
free(temp);
} else {
walker = walker->next;

for (i = 0 ; i < MAX__MONITORS ; i + +f {

> !

fprintff fp, "%s : %d\n",


feed.groups[i].groupName,
feed.groups[i).lastMessageRead ) ;
}

for (i = 0 ; i < MAX_MONITORS ; i++) {


sti].shown)) {
ionitors[i].changed = 0;
lonitors[i].shown = 0;

c l e a r E n t r i e s i n s e r t N e w s I t e m ( 11.23). ,
shown. , , ,
. . n e x t n e x t , . temp
ElementType, , , .

e m i t G r o u p S t a t u s
f e e d .
, ;
.

, HTTP
.. , HTTP- GET ipyer , , 1 ( 1 1 . 2 6 ) .

e m i t C o n f ig ( 11.31). Web-
.


11.31. emitConfig
"<HTMLxHEADxTITI.E>WebAgent</TITI,Ex/HEAD>p
"<BODY TEXT=\"#00G00O\" bgcolor=V#FFFFFF\" link=\"#00DOEE\""
"vlink-\"#551A8B\" alink=\"#FFOOO0\">"
o
"<BRxfont face=\"Bauhaus Md B T V x f o n t color=\"#000000\">

i|||

sprintf(line,
r
<H2>Feed %s</H2><BR><BR>\n", feed.url);
wrice( connfd, line, sCrlen (line) ) ,strcpylline, "<centerxtable B0RDER=3 WIDTH=100% NOSAVExtr>\n") ;
write! connfd, line, strlen(line));
for (i = 0 ; i < MAX_GROUPS ; i++) {

</BODYx/HTML>Nn"

if (feed.groups[i].active) {
sprintf (line, "<trxtdxfont size=+l>Group %s</fontx/td>\n",
feed.groups[il.groupName);
write) connfd, line, strlen(line)|;

- line[MAX_LINE+l];
l monitorEntryType mon
i feedEntryType feed;
mitHTTPResponseHeader( i

/fontxBR><BR>") ; .

for (j = 0 ; j < feed.groups[i].numSearchStrings ; j++) {


if (j > 0) strcatdine, ", -) ,strcatdine, feed, groups [i] . searchStringl j ]) ;
)
} else {
strcatdine, "[*]");
}
strcatdine, -</font>-:/tdx/tr>\n") ;
write! connfd, line, strlen(line) );

; connfd, l i n e , s t r l e n ( l i n e ) ) ;
{line, " < c e n t e r x t a b l e BORDER=3 WlbTH=10D% NOSAVExtr>\n") ;
for (i = 0 ; i < MAX_MONITORS ;
if

(monitors[i].active)

rite( connfd, l i n e , s t r l e n ( l i n e ) ) ;

strcpylline, "</t: </tablex/centerxBRxBR>\n") ;


write! connfd, lii -, strlen(line) ) ;
epilogue, strlen(epilogue));

, 2 HTML-. pgue , .
p i l o g u e HTML-.
HTML- HTML- ( emitHTTPResponseHeader). p r o l o g u e .

>

connf d, . , ,
.
Web-
< t a b l e > .
<tr>. m o n i t o r s , .
, .
, - .
, </table>.
.
s p r i n t f , .
w r i t e .
, m o n i t o r s . ,
. ,
, , . ,
. , , ,. , * ]. ,
.
< / t a b l e > .


strcpydip.e,
"<Hl>Web Agent

||||

Results</Hlx/f ontx/fontxBRxBR>" ];

write( connfd, l i n e , s t r l e n ( l i n e ) | ;
s t r c p y ( l i n e , lp<center>< table BORDER=3 WIDTH=100% NOSAVExtr>\n") ;
w r i t e ! connfd, l i n e , s t r l e n ( l i n e ) ) ;
for (i = 0 ; i < MAX_MONITORS ; i++) {
if ( ( m o n i t o r s [ i ] . a c t i v e ) && (monitors[i].changed)) {

"</fontx/tdx/tr>\n",
monitors[i].url);
write! connfd, line, strlen(line));
monitors[i].shown = 1;

, e p i l o g u e , HTML. , .
, emitNews ( 11.32), ]
eraitConf ig. ( ]
, emitConf ig).

walker - head.next;
if (walker)

11.32. emi tNews


void emitNews( i n t connfd )
line[MAX_LINE+l];
lentType *walker;
:rn monitorEntryType r
:rn feedEntryType feec
;rn elementType head;

itrcpydine, "<centerxtable B0RDER=3 WIDTH=100% NOSAVExtr>\n") ;


i r i t e ( connfd, l i n e , s t r l e n ( l i n e ) ) ,while (walker) {

feed.groups[walker->group].groupName,
walker->link,
walker->subject,
walker->msgDate ) ,-

char line[MAX_LINE+l];
extern feedEntryType feed;

ialker->shown = 1;
zalker = walker->next;

:anf(filename,

"/art%d_%d", &group, ^ a r t i c l e ) ;

write( connfd, l i n e , s t r l e n ( l i n e ) ] ;

>\n");

;trcpy(line,- "<FORM METHOD=\'POST\ ACTION=/clear\">");


jrite< connfd, l i n e , s t r l e n ( l i n e ) ) ,; t rcpy (1 ine, " <BRxBR>< INPUT TYPE= \lp submi t \" "
"VALUE=\"Mark Read\"xBR>\n11) ;
jritef connfd, l i n e , s t r l e n ( l i n e ) ) ;

bzero(news.msg, MAX_NEWS_MSG+1);

1) ;

news.msgLen = MAX_NEWS_MSG;
emitHTTPResponseHeaderl connfd );
write! connfd, prologue, strlen(prologue));
prune( feed.url, line );
count = nntpConnect( line |;
if (count == 0) {
count = nntpSetGroup( feed.groups[group].groupName,
article-1 ) ,-

, ,
monitors ( monitors). , (
a c t i v e ) , ( changed). shown.
, , ( 11.29).
shown , .
, 11.32
, . HTML- < h r e f > . l i n k elementType
(
elementType, 11.23).
, e m i t A r t i c l e , ,
NNTP-, . , . .
, NNTP- ( 11.33).
11.33. emitArticle

if (count > 0) f
result = nntpRetrieve( &news, MAX_NEWS_MSG );
if (result > 0) {
result - nntpparsel &news, FULL_PARSE );
if (result == 0) {
/* */
sprintf( line,
news.subject ) ,sprintff

line,
1
"<font size=+l>Sender : %s\n</font><BRxBR>
news.sender );
write( connfd, l i n e , s t r l e n ( l i n e ) );
sprintff l i n e ,
"<font size=+l>Group : %s\n</font><BR><BR>"
feed.groups[group].groupName );
write( connfd, l i n e , s t r l e n ( l i n e ) I ;
"<BR><BRxhr><PRE>", news.msgDate ) ;

I l l ,
write! connfd, line, strlen(line) );
write! connfd, news.bodyStart, strlenfnews.bodyStart) );
sprintf(line, "</PRExER><BR>End of Message\n<BRxBR>");
write! connfd, line, strlen(line) );

_ | |

[. e m i t A r t i c l e , e p i I B'lo^ufit NNTPI nntpDiscormect.

I
Web-
i n , ( 11.34).
11.34. main () Web-

int Cimer-0,

ret,

/* */
ret = parseConfigFilef "config" I;

:ree( news.msg ] ,-

if (ret != 0) {
printf("Error
exit(D);

intpDisconnect();
/* HTTP- */
initHttpServer() , , ,
. ( HTTP- h a n d l e C o n n e c t i o n ) .
, ,
NNTP-.
( n e w s _ t ) ,
. NNTP- n n t p C o n n e c t .
, / a r t ( f e e d , g r o u p s [ g r o u p ] ). ,
a r t i c l e - 1 . , n n t p S e t G r o u p
, . n n t p R e t r i e v e n n t p P a r s e .
, , , PULL_PARSE n n t p P a r s e ,
.

connfd. , , . - b o d y S t a r t ,

while (1) {
/*
if ((timer % 600) == 0) {
printf('Checking News...\n h I;

10 */

/* */
checkNewsSources(];
printf("Monitoring.-.\n");
/* , !
for (i = 0 ; i < MAX_MONITORS ) i + + ) {

/* , ;
checkHttpServer () ,-

- <

: p a r s e c o n f i g F i l e .
i n i t H t t p S e r v e r HTTP-. , . , - HTTP-.
10 . checkNewsSources , ,
. m o n i t o r S i t e Web-,
. ,
m o n i t o r s .
c h e c k H t t p S e r v e r , HTTP-. \
. ,
, .
,
,
checkHttpServer.


.
?- .
Web- UMBC
Agent BOTSpot (. ). . 11.2
.
11,2.

Internet,
, ..

,
,
.
. , (

). ,
[ , :
| | .


1. Ananova Ltd. (Ananova Agent). http:/
www.ananova.com/video.
2. BotSpot, http://www.botspot.rom.
3. SourceForge. Aglet (Agle
Software Development Kit). http://sourceforee.net/proiects
4. . (Bradshaw J. Software Agents. AAAI Press
MIT Press, 1997).
5. . : (King J. Intelligent Agent:
Bringing Good Things to Life// AI Expert: 17-19, February, 1995).
http://coqui.lce.org/cedu5100/Intelligent Agents.htm.
6. . (Kay A Computer Software /
Scientific American 251(3): 53-59, September, 1994).
7. , . Internet (Uni
versity of Maryland Baltimore Count. Agent Web). http:/
agenLs.umbc.edu/.
8. . . ?
(Franklin S. and Graesser A Is It an Agent or Just a Program? i
Taxonomy for Autonomous Agents // Proceedings of the Third Internationa
Workshop on Agent Theories, Architectures and Languages. - New York: Sprin
ger Verlag, 1996).

CYC ; | | | ]

. , .

12.

, .
, , , .
, ,
, . , .


; . -
,
, . :
.
. .
. ,
, .
- . .
*, .
-,
. ,
, , . , .
; , ,

-, , ,
, .
, .
, -
. , , ,
, ? , , ,
, , , ,
1
. .
, \ . | ,
| , .

CYC
, : , .
,
, . , , ,
. ,
; . , ^ , ?
t

^ CYC . (Doug Lenat);
| , . CYC , .
,
-. CYC , , .
.
, CYC. (6000
60000 ), CYC,
API,
.

1111


1994 . . Geffrey . Kephart) IBM
* (A Biologically Inspired Immune System for
Computers). ,
.

.
IBM ,
,
. , :
,
;
, ;
, ;
, .
. , IT,
, .
, , .


,
. , ,
, ,
, . .
, , .
AM Eurisko , .
, , . BACON.3, . (P. Langley), (
). ,

-:]

, , .
.

,
. , ,
. !
MIT, (Rosalind Picard
. i
, i
.


. , ]
, , !
. , , <
,
. !
. , ;
(GSR)
, .
]
. , !
. ;
, *
.
- , !
, ,
MIT (
. .
, , !
.

MIT. ,
, . :
,
. , oi
.
, , , ;
. '
, (). ,
?, ,
. , , >
. ,

, (, ), , . ,
.

Internet
Internet , , , HTML .
Internet ,
Internet. ,
, , ,
.
Internet - , , . - (Tim Berners-Lee), Internet
HTTP. Internet , . , XML,
, . , Web- :
<BR>
Part Number: 2N2222
<BR>
Type: Transistor
<BR>
Leads: 3
<BR>
Cost: $0.25
XML :

</discrete-part>

,
. XML ,
. HTML Leads Pinss>, .
, HTML ,
. XML- .

: | | |

,
. L
, , ,
, .
, Internet, RDE XML, Web , . RDF ,
URI. URL-, Web, URI. RDF
, . Internet
.
, , . RDF, . ( RDF), .
-
.
Internet.
. , Internet
. .

1. OpenCyc, http://w
.org.
2. Scientific Discovery, h t t p : / ^
Li.org/AlTopics/htmI/discoverv.html.
manticweb.org/.
3. Semantic Web Community Portal, http://'
4. Web- IBM, http://www-3.ihm
autonomic/index, html.
5. Web- MIT (Affective Computing
Group at MIT), http://affect.mediamit.edu/.
6. Web- , http://www.cyc.com.
7. - ., ., . Internet (Bernesr-Lee ., Hendler J., Lassila The Semantic Web // Scientific American,
2001, May). http://www.sciam.com/articie.cfm7articleID00048144-10D2-1C70-84A9809EC588EF21.
8. . :
(Wagman M. Scientific
Discovery Processes in Humans and Computers: Theory and Research in Psychology and Artificial Intelligence. Praeger Publishers, 2000).
9. . // (Kephart J. A Biologically Inspired Immune Systems for

||.

Computers // in Artificial Life 4: Proceedings of the Fourth International Workshop on the Synthesis and Simulation of Living Systems. - Cambridge, Mass:
MIT Press).
10. . AI (Minsky M. Future of AI Technology //
Toshiba Review 47, 7,1992). http://web.rnedia.mit.edu/
-minskv/papers /Causal Diversitv.htmL

,
www.dmk.ru. \
.
.

( !
) 2.
N-.
software/ch2.

( ART1)
, ( ,
) .
.
, ,
. 3 ART1
. :
software/ch3.

- ,
. 4.

.
( ;
software/ch4.

, 5,
,


. .
,
. ,
( ). ( ),
. , . software/ch5.



,
, . 6
. .
software/ch6.



: (. 7).
, . ,
. . . - ( ).
software/ch7.


8 , , .
,

, . software/ch8.


9 , . ,
. , ,
[ , ,
: .
| - ( ) software/ch9.


( ) 10.
, [. [ . , ,
( ). . 10
- . software/chlO.


- . 11 : . ;
-,
Internet. Web- . NNTP HTTP- ( Web). Web- software/chll.


Windows 95,98,2000, Me Cygwin UNIX
www.cvgwin.com> Linux (Red
at 6.1, Linux ); 486 . , 64 , 60 , CD-ROM,
Internet Web- ( Web-).

N 29
71
83
83

243

244
244
244
245
244
244
243

ART1 44
feature vector 44
prototype vector 44
sum vector 49
44
49
- 44
44
61
59
112
114
113
116
114
136
136
114
115
43
63
67
71


83

83
68
67
90
25
N 29
41
40
26
26
25
208

176
229

44
49
49
121
44

116
136
117
116

141
15
16
21
21
21
22
21
22
16
16
68

227
228
227


141
94
85
;
; 90
94

88
86

226
216
215
211

87
88
86
86
67
67

176

.
.

43
ART1 44

211

227
228

175
176
175
176
177
177
177
178
179
178
178

Agent 243
attributes
adaptivity 244
autonomy 244
collaborative 244
communicative 244
mobility 245
personality 244
intelligent 243
Al. CM. Artifical Intelligence
Algorithm
ant 63
Hamiltonian path 67
Job-shop Sheduling Problem 83
Pheromone evaporation 68
Quadratic Assigment 83
tabu list 67
Traveling Salesman Problem 71
ART1 44
applications 61
feature vector 44
optimization 59
prototype vector 44
sum vector 49
backpropagation 90
clustering 43
genetic 112
evaluation 114
initialization 113
operator 116
recombination 115
selection 114
simulated annealing 25
applications 41
current solution 26
N-Quin problem 29
optimization 40
phases 25
working solution 26
ART1 44
vector
feature 44

prototype 44
sum 49

44
44
49
44
61
59
Artifical life 141
Artificial Intelligence 15
strong 16
weak 16 .

Bigram 229
Bigram Model 227

Expert system 175


knowledge base 176
logic system 177
backward 177
forward 177
production rules 175
work phases 178
action 179
conflict resolution 180
match 178
working memory 176

Fuzzy logic 210


hedge 216
membership function 211
operators 215

Genetic operator 116


crossover 116
inversion 136
mutation 117

Knowledge base 176

M
Markov Chain 228
hidden 229
Markov Model 227
hidden 228
Membership function 211
N
Neural network 85
backpropagation algorithm 90
neurocontroller 94
perceptron
multiple layer 88
single layer 86
Neurocontroller 94

Path 67
Hamiltonian 67
Perceptron
multiple layer 88
single layer 86

Pheromone evaporation 68
Problem
Job-shop Sheduling 83
N-Quin 29
Quadratic Asigment 83
Traveling Salesman 71
Production rules 175

Simulated annealing 25
Synthetic ethology 141

Theory
adaptive resonance 43
ART1 44

Vector
feature 44
prototype 44
sum 49
Virtual machine 121

W
Working memory 176