This text and the simulation which illustrates it (program complex6.bas in qbasic, by J.-P. Vanbremeersch) were written in 1997 in order to give a simple example introducing to some concepts used in our Memory Evolutive Systems. They have not been published yet but should appear in the book on the MES we are in the course of drafting.

1. Transport network

Let us model the transport network of a country.

1.1. Characteristics of the net

It is formed by various regular transport lines connecting a locality (city or commune) of the country to another. Some localities are not connected; if a locality N is connected to another, there can exist one or more regular lines (the direction of a line is always specified). The cost of a transport is independent of the specific route taken from its starting point N to its end, but it depends on the means of transport and its characteristics (example: car, coach or train, duration of the travel, comfort, frequency, number of passengers…); this is evaluated by allotting to each transport g a "scale" (of comfort or convenience), represented by an integer p(g). For example a first class carriage will have a higher scale than a 2nd class one. Thus a line is characterized by the locality of departure, the locality of arrival and its scale.

If g is a line from N to N' and g' a line from N' to N", the network also makes it possible to go from N to N" by taking first g and then g'; if g and g' do not have the same scale, the scale allotted to this "multipart" line g.g' from N to N" will be the largest of their two scales (if the journey is made in first class on part of the way, the whole journey is paid at the price of the first class even if the other part is made in 2nd class). In formula:

p(g.g') = max(p(g), p(g')).

1.2. Local area network, targeted networks

The country is divided into wide areas and each area P manages its own local area network; it is a sub-network of the whole network formed of lines connecting the various localities of the area. In general P does not manage the lines connecting it to external localities. However it can exist a locality C to which a certain number of inhabitants of the area must go regularly. Let us think for example of the students of an area without university who will follow the courses of the nearest university; or of the transport of goods towards a more important trading center.

In this case to profit from a better service (more frequent lines, smaller prices), the area can, inside the total network, exploit a specific sub-network towards C, coordinated with its local network. In this targeted network, each locality Pi of the area is connected to C by a particular line (we'll say it is "targeted") qi, ran by the area; the lines qi are chosen so that the following constraint is checked: an inhabitant of Pi can, for the same price, go to C either directly via qi, or indirectly by taking first a local line f from Pi towards a Pj and then the targeted line qj from Pj to C; it means that qi has the same scale as the multipart line f.qj. In other words, the lines qi are such that the scale p(qi) is the largest of the scales of f and qj, for each local line f from Pi to Pj.

1.3. Central node

If the area P has targeted networks towards various external cities, the administration will be simplified if there is a central communication node through which its various targeted networks can transit. Such a central node will be a locality L, generally external to the area, whose site is selected so that the following conditions are satisfied:

The central node makes it possible for example to organize collective tours towards any of the localities C: the members of the group living in the various localities Pi will go individually to L (via the targeted lines li), then all together they will make the journey from L to C. It also allows people external to P and who should go to C crossing P to bypass it instead of penetrating in the area (thus avoiding the internal traffic): they go directly to L then use the central line q from L to C.

If none of the localities to which P is connected in the total network can play the part of a central node, the area may seek to create such a node in an adequate place, by extending the whole network by the organization of the new lines necessary for that. However this operation is not always possible, at least if one makes a point of observing the scale conditions strictly.

1.4. Inter-areas networks

Up to now we have considered a unique area P. Now we will study the transport between two areas. Various localities of P can be connected to localities of another area R by lines of the total network. But to increase their exchanges, the two areas P and R can act in concert to exploit jointly a sub-network and to make of it a true inter-areas network from P to R, coordinated with the local networks of P and R. The necessary properties of such an inter-area network U are the following ones:

In this case, if the area R has a central node M and P a central node L, the inter-areas network U "is integrated " in a line û from L to M. Indeed, in this case the multipart lines made up of a line of U and a selected line from Rk to M form a selected network from P to M, and û is the corresponding central line from L to M. Thus to go from Pi to M a traveler can cross R or go directly from L towards M; indeed, he can go from Pi to L by the selected line li, and then from L to M by û (thus avoiding R), or go from Pi to Rk by a line of U and then from Rk to M by mk.

1.5. Lines between central nodes

If there are inter-areas networks from an area Q to P and from P to R, the multipart transports obtained by composing their lines forms an inter-areas network from Q to R, which is thus integrated in a transport of the central node of Q to that of R.

But the central nodes of two areas can be connected without there being an inter-areas network between them. An extreme case is that of two areas P and P' which have the same central node L without having inter-areas network; this is possible if the two areas have targeted networks towards the same localities.

In this case, if U' are an inter-areas network from an area R' towards P' and U an inter-areas network from P to R, the central nodes M' of R' and M of R are connected by the multipart line û' û; and yet R' and R are not necessarily connected by an inter-areas network. This line makes it possible to go via L without penetrating in the areas P or P'.

Remark. In the preceding example, the scale could be replaced by the break-even point of the line (representing the minimum number of passengers necessary to covering its operating costs).

1.6. How to model the network

The total network is modeled by a category K: Its objects represent the various localities N of the network, an arrow from N to N' represents a line of the network, which will be noted c: N ® N' where c is its scale; the composite of c: N ® N' with c': N' ® N" is the arrow max(c, c'): N ® N" (which represents the multipart line).

To the local network of an area P is associated a pattern of K, also noted P. A targeted network from P to C is modeled by a collective link from P to C (represented by a cone). The area has a central node L if P admits L for its colimit in K.

An inter-areas network U from P to an area R is modeled by a cluster between the patterns which represent them. If P and R have central nodes (thus colimits L and M), it is integrated in the "simple link" û from L to M.

If P does not have a colimit in K, one seeks to add one (modeling a central node) by the process of complexification of K with respect to the strategy consisting in adding a colimit to P. This process applied to several areas simultaneously leads to the introduction of "complex links" which are composites of simple links integrating nonadjacent clusters. They model the multipart lines considered in 1-5, obtained when P and P' have the same central node, and there are inter-areas networks from R' to P' and from P to R.

The conditions for an area P to have a central node in the initial network, or if not to be able to extend this network to add one, will be studied within the more general framework of categories associated with a labeled graph, and illustrated by a simulation in qbasic. In particular it will result from it that, if an area P does not have a central node, it is not always possible to add one which satisfies the constraints on the scales: it is always possible to add an L with a targeted network (li) in which the scale of each li is minimum, and a central line q from L to C for each targeted network from P to C, but the scale of this q is no more given as a function of the scales of the qi.

 

2. Mathematical model

2.1. Category associated to a labeled graph

Here graph will always mean directed multi-graph, i.e., the data of a set of objects and arrows between them. A category can be defined as a graph K equipped with an internal law of composition which associates to 2 consecutive arrows f: A ® B and g: B ® C an arrow f.g: A ® C. This composition must satisfy the 2 axioms:

To a graph G we associate a category C(G), called the category of paths of G, in the following way: It has the same objects that G and the arrows are all the paths (sequence of consecutive arrows) between its objects; the internal composition is defined by taking for the composite of two consecutive paths (f1...,fn) and (g1...,gm) their concatenation (f1...,fn,g1...,gm).

A labeled graph in a monoid H is a graph G equipped with a map p: G ® H associating to each arrow f of G an element p(f) of H, called its weight. (A monoid is a category with only one object.) These weights are extended to C(G) by taking for weight of a path the composite of the weights of its factors in the monoid. By identifying 2 paths which have the same source, the same target and the same weight, we obtain a quotient category of C(G) which has the same objects as G, and whose arrows are the classes of paths with the same weight. This category is called the category associated to the labeled graph (G,p), and it is noted K(G,p).

From now on, we take for H the monoid (N, max) of the integers equipped with the composition max(i, j). The category K(G,p) is then obtained starting from the category of paths of G by identifying 2 paths with the same weight, the weight of a path (f1,…,fn) being max(p(f1),…,p(fn)). In this category, given 2 objects i and j, there exists at most one arrow of weight c from i to j, and thus it will be noted c: i ® j.

The category modeling the transport network (cf. 1.6) is the category associated to the graph formed by the lines of the network, labeled by their scales.

2.2. Existence of a colimit

In a category K, a pattern P is a subgraph of the category which models a set of objects with some distinguished arrows (called links) between them. A collective link from P to an object C is a family of individual links Qi from i to C for each object i of P, compatible with the distinguished links of P in the sense that Qi = F.Qj if F is a distinguished link from i to j. It is represented by a cone with basis P and top C. The pattern has a colimit L in K if there is a collective link (Li) from P to L by which any other collective link (Qi) from P to C factors uniquely, i.e., there exists one and only one Q from L to C such that Qi = Li.Q for each object i of P.

Now let us take for K the category K(G,p) considered at the end of 2.1. If P is a pattern in K a collective link from P to an object C is then a family (qi: i ® C) of arrows from the objects i of P to C such that, for any distinguished link f: i ® j of P, we have qi = max(f, qj).

P admits a colimit L if there is a "canonical" collective link (li: i ® L) from P to L such that, for any collective link (qi: i ® C), there is one and only one link q: L ® C satisfying :

(1) qi = max(li, q) for any object i of P.

This condition imposes very strong constraints on P and the cones. Indeed, it is seen that it is equivalent to the conjunction of the 2 following conditions:

(a) There is a "minimum" cone (li: i ® L), in the sense that li is less or equal to qi for any cone (qi: i ® C) and any object i of P.

(b) For any other cone (qi: i ® C), one has:

Remark. A collective link from P to C also determines a collective link from P' to C, where P' is the pattern obtained by adding to P all the composites of its various links in the category (so that P' is the subcategory of K generated by P). Thus P and P' have the same colimit, if it exists.

2.3. Complexification

If P does not have a colimit in K, the "complexification process" makes it possible to extend K in a "minimal" way into a category K' in which P acquires a colimit. Two cases are possible:

an object L', an arrow li: i ® L' for any object i of P, and, for any cone (qi: i ® C) the arrow min(qi): L' ® C whose composite with each li:® L is equal to qi: i ® C

This defines a category admitting K as a full subcategory and in which (li: i ® L') is a colimit-cone defining L' as the colimit of P. It is also the category associated to the labeled graph obtained by adding to G the object L' and the arrows added to K.

min{qi|q} =max(min{qj|q}, f).

But if (qi: i ® C) does not check the condition (b), one will not be able to put an adequate weight on the arrow which factors it, namely the minimum of the qi.

Let us give a counterexample: P has just 3 objects i, j, k and one arrow 3: i ® j. The other arrows of the category K form a cone of weights 3,3,5 towards C and a cone of weights 4,4,4 towards C'. Then the weights of the links to L' should be 3,3,4, but the arrow q from L' to C factoring the cone toward C cannot be weighted in an adequate way, for its weight d should check: max(d,3)= 4 = max(d,5).

3. Simulation

The construction of a colimit in the category K associated to a graph (G,p) labeled in (N, max) is simulated in "Complex6.bas".

3.1. Hypotheses

The graph G (randomly chosen) has 14 vertices, noted 1 to 14, the weights of which vary from 1 to 10. The associated category K = K(G,p) is constructed by adding to G the composites of 2 consecutive arrows (weighted by the max of their weights), then beginning anew till all the possible composites be obtained.

To simplify, it is assumed that G has at most one arrow from a vertex i to a j and that there exists no arrow from a j > 4 toward an i < 5.

The pattern P is taken as the sub-graph formed by all the arrows between the objects 1, 2, 3, 4; this sub-graph is drawn and its "table" is indicated (bottom right). The sub-category P' of K generated by P is constructed (it is the full sub-category of K with objects 1,2,3,4) by adding to P all the possible composites as above. P' is drawn.

3.2. Collective links from P toward an object C

An object C of K being selected, the arrows of the graph G from an object of P to C are drawn (their value is indicated along the table of P). Their composites with arrows of P' are constructed and drawn; the number of its arrows from i < 5 to C is indicated in the table.

All the possible sequences of 4 arrows (qi: i ® C), i < 5 are formed. Their number is noted (right top), followed by the value of C. Each such sequence is analyzed to see if it defines a collective link from P to C (cone), i.e. if qi = max(qj ,f) for each f: i ® j in P ; in this case the cone is numbered beside C with the weights of its four qi.

3.3. Search of a colimit

(1) max(n, li) = qi for each i < 5.

If this condition is not satisfied, there is no colimit.

If it is satisfied, L is a colimit of P if for each other cone (qi), there exists one and only one arrow n: L ® C in K satisfying (1).

A final drawing shows the different cones and, if it exists, the colimit. The example can be stored.

Remarks. 1. Except at the end, the simulation takes no account of the arrows between objects > 5. In fact, the construction of P' and of the arrows from an i < 5 toward a C for each C is equivalent to the construction of the sub-category K' formed by the arrows with source 1, 2, 3, or 4, and their targets. So it is assumed that G is selected in such a way that K be the union of K' with the set of arrows between objects > 5. [Though values are noted for C < 4, they are not used in the computation; otherwise P' would not be a full sub-category of K and the computation would be more complicated.]

2. If there is no "labeled" complexification, it is nevertheless possible to construct a category in which P admits a colimit (cf. 2.3), but this category is no more labeled in (N, max). This case is not treated in the simulation.

3. The program is easily modified to find a colimit in the case where the labels are in (N, min) or in the additive group of the integers mod M (the "mod M" is necessary to have a finite number of arrows).

 

4. Program

Program by J.-P. Vanbremeersch (1997)

  • DECLARE FUNCTION mini! (d1!, d2!)
  • DECLARE FUNCTION maxi (n1, n2)
  • 'KILL "temps1"
  • TYPE valeur
  • expliq AS STRING * 30
  • tps AS SINGLE
  • END TYPE
  • DIM relation AS valeur
  • SCREEN 12
  • COLOR 14
  • LOCATE 2, 10: PRINT " Voulez-vous partir d'un enregistrement O / N ?"
  • g$ = INPUT$(1)
  • IF UCASE$(g$) = "O" THEN
  • CLEAR
  • GOSUB fichierlit
  • ELSE
  • temporisation = 0
  • END IF
  • IF temporisation = 0 THEN
  • CLEAR : CLS
  • END IF
  • LOCATE 10, 16: PRINT "Pour ralentir le programme,"
  • LOCATE 12, 13: PRINT "tapez 'a', ce qui cr‚era des arrˆts"
  • LOCATE 14, 15: PRINT "sinon n'importe quelle touche."
  • LOCATE 18, 16: PRINT " Mais, en cours de programme"
  • LOCATE 20, 16: PRINT " vous pouvez supprimer ces arrˆts"
  • LOCATE 22, 16: PRINT " en tapant 's' lors d'un arrˆt."
  • k$ = INPUT$(1)
  • CLS
  • DIM rel(4, 4, 10), affich1(15), affich2(15), colF(11)
  • DIM Ki(4, 800), kCone(4, 50, 20), numC(50), pC(4, 10, 15)
  • DIM nbrepC(4, 15)
  • DIM xA(15), yA(15), xx(15), yy(15)
  • DIM dec(50, 50), yz(50)
  • LOCATE 27, 1: PRINT " Choix en cours "
  • ' GOSUB grille
  • GOSUB donnees1
  • GOSUB choix
  • GOSUB pattern
  • FOR nc = 1 TO 14
  • IF nc <= 4 THEN
  • CAN = 1
  • ELSE
  • CAN = 0
  • END IF
  • ERASE Ki
  • gh = 0
  • GOSUB dessin0
  • GOSUB choixC
  • GOSUB composition
  • GOSUB liste
  • GOSUB cones1
  • NEXT nc
  • LOCATE 26, 4: PRINT " Fin des calculs des c"nes;"
  • LOCATE 27, 4: PRINT " pour continuer et changer d'affichage "
  • LOCATE 28, 4: PRINT " tapez sur n'importe quelle touche. "
  • f$ = INPUT$(1)
  • GOSUB donnees2
  • IF cone >= 1 THEN
  • GOSUB colim
  • END IF
  • IF colimite <> 0 THEN
  • GOSUB flechescol
  • END IF
  • IF cone = 0 THEN
  • LOCATE 26, 1: PRINT " Pas de C"ne. Pas de Colimite. "
  • END IF
  • f$ = INPUT$(1)
  • IF temporisation = 0 THEN 'c...d., si ne s'agit pas d'un exemple enregistr‚
  • GOSUB fichierenregistre
  • END IF
  • END
  • flechescol:
  • FOR d = 1 TO cone
  • cp = 9: dec = 0: dec0 = 0: KOL = 1
  • IF d <> colimite THEN
  • FOR i = 1 TO 4
  • IF pC(i, kCone(i, d, numC(d)), numC(d)) = pC(i, kCone(i, colimite, numC(colimite)), numC(colimite)) THEN
  • cp = mini(cp, pC(i, kCone(i, d, numC(d)), numC(d)))
  • ELSEIF pC(i, kCone(i, d, numC(d)), numC(d)) > pC(i, kCone(i, colimite, numC(colimite)), numC(colimite)) THEN
  • dec0 = pC(i, kCone(i, d, numC(d)), numC(d))
  • IF dec = 0 THEN
  • dec = dec0
  • END IF
  • END IF
  • IF dec0 <> dec OR dec > cp THEN
  • KOL = 0
  • END IF
  • NEXT i
  • END IF
  • IF KOL = 1 THEN
  • dec(colimite, d) = dec
  • IF dec = 0 THEN
  • dec(d, colimite) = 0
  • col = 15
  • ELSE
  • col = colF(dec(colimite, d))
  • END IF
  • COLOR col
  • LOCATE yz(d), 77: PRINT dec(colimite, d)
  • IF numC(d) = numC(d + 1) AND d < cone THEN
  • haut = haut + 3
  • ELSE
  • haut = 0
  • END IF
  • LINE (xA(numC(colimite)), yA(numC(colimite)))-(xA(numC(d)), yA(numC(d)) + haut), col
  • COLOR 15
  • LOCATE yz(colimite), 77: PRINT "Cmin"
  • ELSE
  • LOCATE 28, 1: PRINT " Pas de COMPLEX "
  • pascomplex = 1
  • END IF
  • NEXT d
  • RETURN
  • liste:
  • ' top
  • r = 1
  • FOR l = 1 TO nbrepC(1, nc)
  • FOR m = 1 TO nbrepC(2, nc)
  • FOR n = 1 TO nbrepC(3, nc)
  • FOR o = 1 TO nbrepC(4, nc)
  • Ki(1, r) = l
  • Ki(2, r) = m
  • Ki(3, r) = n
  • Ki(4, r) = o
  • ' LOCATE r, 1: PRINT Ki(1, r), Ki(2, r), Ki(3, r), Ki(4, r)
  • r = r + 1
  • NEXT o, n, m, l
  • ycone = ycone + 1
  • IF nc > 4 THEN
  • COLOR 15
  • ELSE
  • COLOR col(nc)
  • END IF
  • LOCATE ycone, 56: PRINT r
  • LOCATE ycone, 60: PRINT "C"; nc
  • COLOR 15
  • RETURN
  • cones1:
  • non = 0
  • FOR liste = 1 TO r
  • LOCATE 27, 1: PRINT " Calculs c"nes en cours "
  • oui = 1
  • FOR i = 1 TO 4
  • FOR j = 1 TO 4
  • FOR h1 = 1 TO nbre(i, j)
  • IF maxi(rel(i, j, h1), pC(j, Ki(j, liste), nc)) <> pC(i, Ki(i, liste), nc) THEN
  • oui = 0
  • END IF
  • NEXT h1
  • NEXT j
  • NEXT i
  • IF oui = 1 THEN
  • gh = gh + 1
  • cone = cone + 1
  • numC(cone) = nc
  • kCone(1, cone, nc) = Ki(1, liste)
  • kCone(2, cone, nc) = Ki(2, liste)
  • kCone(3, cone, nc) = Ki(3, liste)
  • kCone(4, cone, nc) = Ki(4, liste)
  • GOSUB affichcone
  • END IF
  • NEXT liste
  • LOCATE 27, 1: PRINT " Calculs c"nes effectu‚s"
  • GOSUB texte
  • RETURN
  • 'top
  • conemini:
  • cone = cone + 1
  • colimite = cone
  • yz(cone) = 23
  • CIRCLE (xA(15), yA(15)), 15, 2: PAINT (xA(15), yA(15) - 6), 15, 2
  • LOCATE 1, xx(15) + 5: PRINT "C 15 mini"; STR$(min(1)); STR$(min(2)); STR$(min(3)); STR$(min(4))
  • numC(colimite) = 15
  • FOR i = 1 TO 4
  • pC(i, kCone(i, 15, numC(colimite)), numC(colimite)) = min(i)
  • LINE (xP(i), yP(i))-(xA(15), yA(15)), 15
  • NEXT i
  • GOSUB flechescol
  • RETURN
  • colim:
  • FOR i = 1 TO 4
  • min(i) = pC(i, kCone(i, 1, numC(1)), numC(1))
  • NEXT i
  • FOR d = 2 TO cone
  • FOR i = 1 TO 4
  • IF pC(i, kCone(i, d, numC(d)), numC(d)) < min(i) THEN
  • min(i) = pC(i, kCone(i, d, numC(d)), numC(d))
  • END IF
  • NEXT i
  • NEXT d
  • FOR d = 1 TO cone
  • co = 0
  • FOR i = 1 TO 4
  • IF pC(i, kCone(i, d, numC(d)), numC(d)) = min(i) THEN
  • co = co + 1
  • END IF
  • NEXT i
  • IF co = 4 THEN
  • colimite = d
  • ELSE
  • co = 0
  • END IF
  • NEXT d
  • IF colimite <> 0 THEN
  • LOCATE 28, 1: PRINT " COLIMITE = c"ne "; colimite
  • ELSE
  • LOCATE 28, 1: PRINT " Pas de COLIMITE "
  • GOSUB conemini
  • END IF
  • GOSUB affichcolimite
  • RETURN
  • composition:
  • LOCATE 27, 1: PRINT " Calculs composition en cours "
  • DO
  • tour = 0
  • FOR i = 1 TO 4
  • IF nbrepC(i, nc) <> 10 THEN
  • FOR j = 1 TO 4
  • FOR k = 1 TO nbre(i, j)
  • non = 0
  • IF i <> j AND rel(i, j, k) <> 0 THEN
  • FOR hh = 1 TO nbrepC(j, nc)
  • FOR h = 1 TO nbrepC(i, nc)
  • IF maxi(rel(i, j, k), pC(j, hh, nc)) = pC(i, h, nc) THEN
  • non = 1
  • END IF
  • NEXT h
  • IF non = 1 THEN EXIT FOR
  • IF non = 0 AND CAN = 0 THEN
  • nbrepC(i, nc) = nbrepC(i, nc) + 1
  • pC(i, nbrepC(i, nc), nc) = maxi(rel(i, j, k), pC(j, hh, nc))
  • tour = 1
  • GOSUB affichC
  • END IF
  • IF non = 0 AND CAN = 1 AND i <> nc THEN
  • nbrepC(i, nc) = nbrepC(i, nc) + 1
  • pC(i, nbrepC(i, nc), nc) = maxi(rel(i, j, k), pC(j, hh, nc))
  • tour = 1
  • GOSUB affichC
  • END IF
  • NEXT hh
  • END IF
  • NEXT k
  • NEXT j
  • END IF
  • NEXT i
  • LOOP UNTIL tour = 0
  • LOCATE 27, 1: PRINT " Calculs composition effectu‚s"
  • GOSUB texte
  • RETURN
  • pattern:
  • LOCATE 27, 1: PRINT " Calculs pattern en cours "
  • DO
  • calc = 0
  • FOR i1 = 1 TO 4
  • FOR j1 = 1 TO 4
  • FOR h1 = 1 TO nbre(i1, j1)
  • FOR k1 = 1 TO 4
  • IF nbre(i1, k1) <> 10 THEN
  • FOR h2 = 1 TO nbre(j1, k1)
  • non = 0
  • P = maxi(rel(i1, j1, h1), rel(j1, k1, h2))
  • FOR s = 1 TO nbre(i1, k1)
  • IF rel(i1, k1, s) = P THEN
  • non = 1
  • END IF
  • NEXT s
  • IF non = 1 THEN EXIT FOR
  • IF non = 0 THEN
  • 'c = c + 1
  • 'LOCATE 1, 1: PRINT c
  • nbre(i1, k1) = nbre(i1, k1) + 1
  • rel(i1, k1, s) = P
  • kk = s
  • i = i1: j = k1
  • calc = 1
  • GOSUB affichIJ
  • END IF
  • NEXT h2
  • END IF
  • NEXT k1
  • NEXT h1
  • NEXT j1
  • NEXT i1
  • LOOP UNTIL calc = 0
  • LOCATE 27, 1: PRINT " Calculs pattern effectu‚s"
  • GOSUB texte
  • RETURN
  • choix:
  • choix = 0
  • IF temporisation = 0 THEN
  • temps = TIMER
  • END IF
  • RANDOMIZE temps
  • LOCATE 1, 10: PRINT "RANDOM ="; temps
  • ERASE rel
  • FOR i = 1 TO 4
  • FOR j = 1 TO 4
  • rel = INT(RND * 2)
  • kk = 0
  • IF i <> j AND rel <> 0 AND rel(j, i, 1) = 0 THEN
  • rel = INT(RND * 10)
  • rel(i, j, 1) = rel
  • rel1(i, j, 1) = rel
  • IF rel <> 0 THEN
  • nbre1(i, j) = nbre1(i, j) + 1
  • nbre(i, j) = nbre(i, j) + 1
  • END IF
  • kk = 1
  • END IF
  • GOSUB affichIJ
  • i1 = i: j1 = j
  • NEXT j
  • NEXT i
  • FOR i = 1 TO 4
  • LOCATE y(i), x(i): PRINT i
  • NEXT i
  • choix = 1
  • LOCATE 27, 1: PRINT " Choix initial effectu‚"
  • GOSUB texte
  • RETURN
  • choixC:
  • choixC = 0
  • suiteC = 0
  • FOR i = 1 TO 4
  • rel = INT(RND * 10)
  • pC(i, 1, nc) = rel
  • IF rel <> 0 THEN
  • nbrepC(i, nc) = 1
  • END IF
  • IF CAN = 1 AND i = nc THEN
  • pC(i, 1, nc) = 0
  • END IF
  • GOSUB affichC
  • NEXT i
  • LOCATE 27, 1: PRINT " Choix C effectu‚."
  • GOSUB texte
  • choix = 1
  • choixC = 1
  • suite = 3
  • suiteC = 3
  • RETURN
  • affichcone:
  • IF nc > 4 THEN
  • col = 1
  • ELSE
  • col = col(nc)
  • END IF
  • LOCATE yy(nc), xx(nc): PRINT nc
  • CIRCLE (xA(nc), yA(nc)), 15, 15: PAINT (xA(nc), yA(nc) - 6), col, 15
  • IF nc > 4 THEN
  • COLOR 15
  • ELSE
  • COLOR col(nc)
  • END IF
  • IF gh > 1 THEN
  • ycone = ycone + 1
  • END IF
  • yz(cone) = ycone
  • LOCATE ycone, 65: PRINT "/c"";
  • LOCATE ycone, 68: PRINT RIGHT$(STR$(cone), 2)
  • LOCATE ycone, 71: PRINT RIGHT$(STR$(pC(1, kCone(1, cone, nc), nc)), 1)
  • LOCATE ycone, 72: PRINT RIGHT$(STR$(pC(2, kCone(2, cone, nc), nc)), 1)
  • LOCATE ycone, 73: PRINT RIGHT$(STR$(pC(3, kCone(3, cone, nc), nc)), 1)
  • LOCATE ycone, 74: PRINT RIGHT$(STR$(pC(4, kCone(4, cone, nc), nc)), 1)
  • COLOR 15
  • RETURN
  • affichcolimite:
  • IF colimite <> 0 AND pascomplex = 0 THEN
  • col = 15
  • nc = numC(colimite)
  • CIRCLE (210, 350), 90, 0, , , .75
  • LINE (xP(1) - 10, yP(1) + 10)-(xA(nc), yA(nc)), col: LINE -(xP(3) + 10, yP(1) + 10), col: LINE -(xP(1) - 10, yP(1) + 10), col
  • PAINT (xP(1) + 20, yP(1) - 2), 15, 15
  • END IF
  • FOR i = 1 TO 4
  • FOR d = 1 TO cone
  • IF d <> colimite THEN
  • col = colF(pC(i, kCone(i, d, numC(d)), numC(d)))
  • LINE (xP(i), yP(i))-(xA(numC(d)), yA(numC(d))), col
  • END IF
  • NEXT d, i
  • FOR i = 1 TO 14
  • IF i > 4 THEN
  • col = 1
  • ELSE
  • col = col(i)
  • END IF
  • LOCATE yy(i), xx(i): PRINT i
  • CIRCLE (xA(i), yA(i)), 15, 15: PAINT (xA(i), yA(i) - 6), col, 15
  • NEXT i
  • GOSUB dessin01
  • RETURN
  • affichIJ:
  • x = 0: y = 0
  • IF nbre(i, j) <> 1 THEN
  • x = xvar(i, j) * nbre(i, j): y = yvar(i, j) * nbre(i, j)
  • END IF
  • IF choix = 0 THEN
  • IF kk <> 0 THEN
  • COLOR colF(rel(i, j, kk))
  • LOCATE i + 24, j * 3 + 45: PRINT rel(i, j, kk)
  • COLOR 15
  • END IF
  • END IF
  • IF rel(i, j, kk) = 0 THEN
  • col = 0
  • ELSE
  • col = colF(rel(i, j, kk))
  • END IF
  • LINE (xP(i), yP(i))-(xP(i) + affich3(i, j) + x, yP(i) + affich4(i, j) + y), col: LINE -(xP(j), yP(j)), col
  • LINE (xP(i) + affich3(i, j) + fche1(i, j) + x, yP(i) + affich4(i, j) + fche2(i, j) + y)-(xP(i) + affich3(i, j) + x, yP(i) + affich4(i, j) + y), col
  • LINE (xP(i) + affich3(i, j) + fche3(i, j) + x, yP(i) + affich4(i, j) + fche4(i, j) + y)-(xP(i) + affich3(i, j) + x, yP(i) + affich4(i, j) + y), col
  • RETURN
  • affichC:
  • IF suiteC = 0 THEN
  • LOCATE i + 24, 70 + 3: PRINT " "
  • END IF
  • LOCATE i + 24, 65: PRINT i; "C "
  • LOCATE i + 24, 70 + suiteC: PRINT nbrepC(i, nc)
  • n = nbrepC(i, nc)
  • col = colF(pC(i, n, nc))
  • IF choixC = 0 THEN
  • COLOR col
  • LOCATE i + 24, 58 + 3: PRINT pC(i, n, nc)
  • COLOR 15
  • END IF
  • LINE (xP(i), yP(i))-(xP(i) + affich1(n), yP(i) + affich2(n)), col: LINE -(xA(nc), yA(nc)), col
  • LINE (xP(i) + affich1(n) - 5, yP(i) + affich2(n) + 5)-(xP(i) + affich1(n), yP(i) + affich2(n)), col
  • LINE (xP(i) + affich1(n) + 5, yP(i) + affich2(n) + 5)-(xP(i) + affich1(n), yP(i) + affich2(n)), col
  • IF nc > 4 THEN
  • col = 1
  • ELSE
  • col = col(nc)
  • END IF
  • LOCATE yy(nc), xx(nc): PRINT nc
  • CIRCLE (xA(nc), yA(nc)), 15, 2: PAINT (xA(nc), yA(nc) - 6), col, 2
  • RETURN
  • dessin01:
  • CIRCLE (210, 350), 90, 3, , , .75: PAINT (210, 350), 0, 3: CIRCLE (210, 350), 90, 15, , , .75
  • FOR i = 1 TO 4
  • FOR j = 1 TO 4
  • IF rel1(i, j, 1) <> 0 THEN
  • col = colF(rel(i, j, 1))
  • LINE (xP(i), yP(i))-(xP(i) + affich3(i, j), yP(i) + affich4(i, j)), col: LINE -(xP(j), yP(j)), col
  • LINE (xP(i) + affich3(i, j) + fche1(i, j), yP(i) + affich4(i, j) + fche2(i, j))-(xP(i) + affich3(i, j), yP(i) + affich4(i, j)), col
  • LINE (xP(i) + affich3(i, j) + fche3(i, j), yP(i) + affich4(i, j) + fche4(i, j))-(xP(i) + affich3(i, j), yP(i) + affich4(i, j)), col
  • END IF
  • NEXT j
  • CIRCLE (xP(i), yP(i)), 15, col(i): PAINT (xP(i), yP(i) + 1), col(i), col(i)
  • LOCATE y(i), x(i): PRINT i
  • NEXT i
  • RETURN
  • donnees1:
  • DATA 4,5,6,9,10,11,12,13,14
  • FOR i = 1 TO 9
  • READ colF(i)
  • LINE (10, i * 16 + 10)-(30, i * 16 + 8), colF(i), BF
  • COLOR colF(i)
  • LOCATE i + 1, 1: PRINT i
  • NEXT i
  • COLOR 15
  • FOR i = 1 TO 4
  • COLOR 14
  • LOCATE 22, 49: PRINT "Choix init."
  • LOCATE i + 24, 44: PRINT i
  • LOCATE 23, i * 3 + 45: PRINT i
  • NEXT i
  • LINE (350, 380)-(370, 360): LINE (370, 360)-(365, 370): LINE (370, 360)-(360, 365)
  • COLOR 9: LOCATE 23, 61: PRINT " C"
  • COLOR 15
  • DATA 0,-3,0,-3,-2,-2,0,3,-2,-2,2,-2,0,3,-2,-2,-2,-3,2,2,2,-2,-1,3
  • FOR i = 1 TO 4
  • FOR j = 1 TO 4
  • IF i <> j THEN
  • READ xvar(i, j), yvar(i, j)
  • END IF
  • NEXT j
  • NEXT i
  • DATA 130,15,160,-30,60,-60
  • DATA -130,30,50,0,-40,-50
  • DATA -160,30,-35,20,-120,-50
  • DATA -60,60,50,50,80,10
  • FOR i = 1 TO 4
  • FOR j = 1 TO 4
  • IF i <> j THEN
  • READ affich3(i, j), affich4(i, j)
  • END IF
  • NEXT j
  • NEXT i
  • DATA -5,-5,-5,5,-5,-5,-5,5,-6,-1,0,6
  • DATA 5,-5,5,5,-6,-5,-5,5,8,3,0,8
  • DATA 5,-5,5,5,6,-1,0,-6,7,-3,4,7
  • DATA 6,-1,0,-6,-10,-3,0,-8,-7,4,-4,-7
  • FOR i = 1 TO 4
  • FOR j = 1 TO 4
  • IF i <> j THEN
  • READ fche1(i, j), fche2(i, j), fche3(i, j), fche4(i, j)
  • END IF
  • NEXT j
  • NEXT i
  • FOR i = 1 TO 14
  • xA(i) = 200: yA(i) = 50
  • yy(i) = 2: xx(i) = 24
  • NEXT i
  • nc = 1
  • DATA 75,343,9,22,11,325,343,40,22,12,405,295,50,19,13,198,248,24,16,14
  • FOR i = 1 TO 4
  • READ xP(i), yP(i), x(i), y(i), col(i)
  • xP(i) = xP(i) - 5
  • NEXT i
  • DATA -35,-30,-25,-20,-15,-10,-5,0,5,10,15,20,25,30
  • FOR k = 1 TO 14
  • affich2(k) = -120
  • READ affich1(k)
  • NEXT k
  • col = 1
  • GOSUB dessin0
  • RETURN
  • dessin0:
  • FOR i = 1 TO 4
  • FOR k = 1 TO 14
  • LINE (xP(i), yP(i))-(xP(i) + affich1(k), yP(i) + affich2(k)), 8: LINE -(xA(nc), yA(nc)), 8
  • LINE (xP(i) + affich1(k) - 5, yP(i) + affich2(k) + 5)-(xP(i) + affich1(k), yP(i) + affich2(k)), 8
  • LINE (xP(i) + affich1(k) + 5, yP(i) + affich2(k) + 5)-(xP(i) + affich1(k), yP(i) + affich2(k)), 8
  • NEXT k
  • CIRCLE (xP(i), yP(i)), 20, col(i): PAINT (xP(i), yP(i) + 11), col(i), col(i)
  • LOCATE y(i), x(i): PRINT i
  • NEXT i
  • CIRCLE (xA(nc), yA(nc)), 15, 15: PAINT (xA(nc), yA(nc) - 6), col, 15
  • LOCATE yy(nc), xx(nc): PRINT nc
  • RETURN
  • donnees2:
  • LINE (30, 1)-(350, 490), 0, BF
  • LINE (350, 1)-(435, 337), 0, BF
  • LINE (350, 337)-(380, 385), 0, BF
  • COLOR 14: LINE (350, 380)-(370, 360): LINE (370, 360)-(365, 370): LINE (370, 360)-(360, 365)
  • COLOR 15
  • DATA 45,-10,45,-40,0,-40
  • DATA -45,10,30,-15,-20,-40
  • DATA -65,20,15,40,-35,-5
  • DATA -20,35,20,45,40,-5
  • FOR i = 1 TO 4
  • FOR j = 1 TO 4
  • IF i <> j THEN
  • READ affich3(i, j), affich4(i, j)
  • END IF
  • NEXT j
  • NEXT i
  • DATA -5,-5,-5,5,-10,3,-3,10,-6,5,4,7
  • DATA 5,-5,5,5,-10,0,-5,8,10,5,0,10
  • DATA 10,-8,13,0,-7,-8,2,-10,8,-3,8,5
  • DATA 10,-3,0,-10,-10,-3,0,-10,-8,6,-8,-5
  • FOR i = 1 TO 4
  • FOR j = 1 TO 4
  • IF i <> j THEN
  • READ fche1(i, j), fche2(i, j), fche3(i, j), fche4(i, j)
  • END IF
  • NEXT j
  • NEXT i
  • DATA 160,375,19,24,11,248,375,30,24,12,273,327,33,21,13,192,310,23,20,14
  • FOR i = 1 TO 4
  • READ xP(i), yP(i), x(i), y(i), col(i)
  • xP(i) = xP(i) - 5
  • NEXT i
  • DATA -35,-30,-25,-20,-15,-10,-5,0,5,10,15,20,25,30
  • FOR k = 1 TO 14
  • affich2(k) = -120
  • READ affich1(k)
  • NEXT k
  • GOSUB dessin01
  • DATA 7,22,4,18,9,15,9,11,11,7
  • DATA 20,12,22,9,28,9,32,12,39,7
  • DATA 41,11,41,15,46,18,43,22,25,5
  • FOR i = 1 TO 15
  • READ xx(i), yy(i)
  • yy(i) = yy(i) - 4
  • NEXT i
  • DATA 75,53,93,93,108,180,197
  • DATA 245,277,339,354,354,394,370,226
  • FOR i = 1 TO 15
  • READ xA(i)
  • xA(i) = xA(i) - 18
  • yA(i) = yy(i) * 288 / 18 - 9
  • IF i < 15 THEN
  • LOCATE yy(i), xx(i): PRINT i
  • IF i > 4 THEN
  • col = 1
  • ELSE
  • col = col(i)
  • END IF
  • CIRCLE (xA(i), yA(i)), 15, 15: PAINT (xA(i), yA(i) - 6), col, 15
  • END IF
  • NEXT i
  • RETURN
  • grille:
  • FOR i = 1 TO 50
  • x = x + 1
  • LINE (i * 10, 10)-(i * 10, 500)
  • IF x = 10 THEN
  • LINE (i * 10, 10)-(i * 10, 500), 13
  • x = 0
  • END IF
  • NEXT i
  • FOR i = 1 TO 50
  • x = x + 1
  • LINE (10, i * 10)-(500, i * 10)
  • IF x = 10 THEN
  • LINE (10, i * 10)-(500, i * 10), 13
  • x = 0
  • END IF
  • NEXT i
  • RETURN
  • texte:
  • IF UCASE$(k$) = "A" THEN
  • LOCATE 28, 1: PRINT " Tapez sur une touche"
  • f$ = INPUT$(1)
  • IF UCASE$(f$) = "S" THEN
  • k$ = ""
  • END IF
  • END IF
  • LOCATE 26, 1: PRINT " "
  • LOCATE 27, 1: PRINT " "
  • LOCATE 28, 1: PRINT " "
  • RETURN
  • fichierenregistre:
  • LINE (1, 1)-(350, 490), 0, BF
  • LINE (350, 1)-(435, 337), 0, BF
  • LINE (350, 337)-(380, 385), 0, BF
  • LOCATE 1, 1
  • OPEN "C:\Basic\Temps1" FOR RANDOM AS #1
  • itemps = 0
  • SEEK #1, 1
  • DO WHILE NOT EOF(1)
  • itemps = itemps + 1
  • GET #1, itemps, relation
  • IF relation.tps <> 0 AND relation.expliq <> "" THEN
  • PRINT "nø"; itemps; "/ tps ="; relation.tps; ".."; relation.expliq
  • END IF
  • LOOP
  • PRINT
  • PRINT " Voulez-vous enregistrer cet exemple O / N ?"
  • g$ = INPUT$(1)
  • PRINT
  • IF UCASE$(g$) = "O" THEN
  • PRINT "Inscrivez votre commentaire "
  • itemps = SEEK(1) - 2
  • PRINT itemps + 1, temps
  • itemps = itemps + 1
  • INPUT g$
  • relation.expliq = g$
  • relation.tps = temps
  • PUT #1, itemps, relation
  • GET #1, itemps, relation: PRINT "nø"; itemps; "/ tps ="; relation.tps; ".."; relation.expliq
  • CLOSE #1
  • ELSE
  • CLOSE #1
  • END IF
  • RETURN
  • fichierlit:
  • OPEN "C:\Basic\Temps1" FOR RANDOM AS #1
  • itemps = 0
  • SEEK #1, 1
  • DO WHILE NOT EOF(1)
  • itemps = itemps + 1
  • GET #1, itemps, relation
  • IF relation.tps <> 0 AND relation.expliq <> "" THEN
  • PRINT "nø"; itemps; "/ tps ="; relation.tps; ".."; relation.expliq
  • END IF
  • LOOP
  • PRINT
  • DO
  • INPUT "Lequel voulez-vous ? "; c
  • GET #1, c, relation
  • PRINT "nø "; relation.tps; "... "; relation.expliq
  • PRINT
  • PRINT "Si vous ˆtes d'accord, tapez 'O', sinon 'N'"
  • PRINT "Si vous voulez revenir ... la randomisation, tapez 'R'"
  • gg$ = INPUT$(1)
  • IF UCASE$(gg$) = "O" THEN
  • temps = relation.tps
  • OK = 1
  • temporisation = 1
  • ELSEIF UCASE$(gg$) = "R" THEN
  • temporisation = 0
  • OK = 1
  • ELSEIF UCASE$(gg$) = "N" THEN
  • OK = 0
  • END IF
  • LOOP UNTIL OK = 1
  • CLOSE #1
  • CLS
  • RETURN
  • FUNCTION maxi (n1, n2)
  • IF n1 >= n2 THEN
  • maxi = n1
  • ELSEIF n1 < n2 THEN
  • maxi = n2
  • END IF
  • END FUNCTION
  • FUNCTION mini (d1, d2)
  • IF d1 < d2 THEN
  • mini = d1
  • ELSEIF d1 >= d2 THEN
  • mini = d2
  • END IF
  • END FUNCTION