• No se han encontrado resultados

Gestión de Recursos 45.1. Gestión de Capital

In document 0201LUAN E A M FOR IN INFORME ANUAL 2010 (página 95-100)

The algorithms in this subsection find maximal program subsets and max- imal schemata by exploiting a property of what this thesis means by “max- imal”: any proper superset a of a maximal schema am is represented by a

maximal schema which is itself a proper superset of am. Similarly, any

proper superset a of a maximal program subset am is represented by a

maximal program subset which is itself a proper superset of am. By using

this property, combined with a method for “promoting” the schema/program subset a to its maximal representative, the algorithms of this section may efficiently find the desired set of maximal program subsets/schemata.

In terms of the meet-semi-lattice, the meet of a collection of sets is the largest set which has each set in the collection as a superset, that is the intersection of the sets. Any set which is a one-step addition to a given meet is be represented by a proper superset of the original meet.

One considerable advantage of these algorithms over those described previously in section 5.5.1 is that, with little extra complexity, they may ar- range the output sets of maximal program subsets and maximal schemata into an anti-transitive directed acyclic graph (DAG) with edges indicat- ing a general/specific relation. The new method requires the edges of this DAG in order to count the number of program subsets or schemata rep- resented by each maximal program subset or maximal schema and this count in turn allows more powerful analysis. By contrast, the algorithms of section 5.5.1 require an additional expensive algorithm to identify the edges in this DAG.

This section describes two algorithms equivalent in input and output: • A simple algorithm, PromoteIncrement-simple.

• A more complicated algorithm, PromoteIncrement-hash with improved complexity.

PromoteIncrement-simple

PromoteIncrement-simple is the simpler of the two algorithms utilizing this promote/increment approach to finding the meet-semi-lattice of max-

imal schemata and maximal program subsets. The main function PromoteIncrement- simple in turn calls a recursive function recurse on singleton set {a} for

each key a found in the given map M . recurse then promotes this single- ton set to its representing maximal set, Am, which is stored in the output

set R. In the following increment step the recurse function recurses on each possible one-step addition to the input singleton set A. Each one- step-addition set is represented by a proper superset of the Am from the

5.5. ADDMEETS: GET MEETS FROM MAPPING 119 Thus recurse promotes the one-step-addition set and the resultant rep- resenting set is added to R. recurse then recurses on each minimally larger set.

PromoteIncrement-simpleis presented in pseudocode 5.6. The opera-

FUNCTION PromoteIncrement-simple(M ) // M is a mapping from A’s to sets of B’s Set of pairs R = {} FOR EACH< a → B >∈ M recurse({a}) RETURN(R) END FUNCTION recurse(A) // A is a set of sets of A’s initialize set Bm FOR EACHain A Bm = Bm∩ {b : b ∈ B, < a → B >∈ M } FOR EACHbin Bm Am = Am∩ {a :< a → B0 >∈ M, B0 ⊇ Bm} IF< Am, Bm >6∈ R R = R ∪ < Am, Bm >

FOR EACH< a → B >∈ M where a 6∈ Am

recurse({a} ∪ Am)

END

Pseudocode 5.6: PromoteIncrement-simple

tion of the PromoteIncrement-simple is as follows:

• The main function, PromoteIncrement-simple, presents the recursive procedure with each singleton set of A’s.

• The recursive function, recurse takes a set of A’s, A, which is not necessarily maximal.

• recurse then finds the maximal set of B’s for A as Bm.

• A similar operation finds the maximal set of A’s for Bm. This process

produces Am which must represent A. The process also, usefully,

finds it’s mate Bm. If Amis a maximal schema, Bmwill be the largest

program subset matching all schema components of Am. If Am is a

maximal program subset, Bm will be the largest set of schema com-

ponents occurring in all programs of Am.

• The recurse function recurses on one-step-additions to the maximal set Am. It also restricts unnecessary repeated calls by testing whether

a given Amhas previously been found and only recursing if it hasn’t.

Each of the initial singleton sets may or may not be maximal, but any set of A’s that is maximal must be a superset of one or more of the singleton sets. Any maximal set of A’s must either represent one of these single- ton sets or must be a proper superset of a maximal set which represents one of these singleton sets. Thus given that the function recurse finds all maximal sets of A’s which are supersets of the input set, the outer call to PromoteIncrement-simplewill find all desired maximal sets of A’s.

Complexity

Let the mapping M have |A| members and a limit of |B| on mapped-to set size. Also let the output set have |R| members.

The IF statement in recurse ensures that the function doesn’t recurse unless Am is new to the output set, thus the statement after theIFis called

exactly |R| times. Therefore, recurse is called no more than |R||A| times. Each call to recurse entails finding Bm(O(|A||B|)) then finding Am(also

O(|A||B|)). Thus the initial part of recurse, called |R||A| times, contributes O(|R||A|2|B|) to the complexity.

5.5. ADDMEETS: GET MEETS FROM MAPPING 121 The statements after the if are called |R| times with O(|A|) each time and thus do not contribute to the overall worst case complexity.

Thus the complexity of the call to PromoteIncrement-simple is O(|R||A|2|B|)

where there are |R| maximal pairs found, there are |A| A’s in M and there are |B| B’s mapped to in M .

Let the mapping M have |A| members and a limit of |B| on mapped-to set size. Also let the output set have |R| members.

The IF statement in recurse ensures that the function doesn’t recurse

unless Amis new to the output set, thus the statement after theIFis called

exactly |R| times. Therefore, recurse is called no more than |R||A| times. Each call to recurse entails finding Bm(O(|A||B|)) then finding Am(also

O(|A||B|)). Thus the initial part of recurse, called |R||A| times, contributes O(|R||A|2|B|) to the complexity.

The statements after the if are called |R| times with O(|A|) each time and thus do not contribute to the overall worst case complexity.

Thus this complexity of the call to PromoteIncrement-simple is O(|R||A|2|B|)

where there are |R| maximal pairs found, there are |A| A’s in M and there are |B| B’s mapped to in M .

PromoteIncrement-hash

PromoteIncrement-hashis similar in operation to the previously described algorithm, also utilizing a promote/increment approach to finding the de- sired maximal schemata and maximal program subsets. But the increment step has been enhanced to improve the algorithm’s complexity.

As with PromoteIncrement-simple, the main function PromoteIncrement- hash in turn calls a recursive function recurse on a number of base sets, however, in contrast to the singleton sets used by PromoteIncrement-simple PromoteIncrement-hashuses minimally maximal sets of A0s, that is the small-

est maximal proper supersets of the input set, which are found using a function findMinimals.

the respective maximal set of B’s as Bm, thus completing the maximal pair

< Am, Bm >. The returned set contains each such pair found. In the case

where the recurse function hasn’t yet been called with this Am, the func-

tion recurses on each minimally maximal proper superset of Am. These

supersets are found using the function findMinimals.

PromoteIncrement-hash is presented in pseudocode 5.7. The opera- tion of PromoteIncrement-hash is as follows:

• The function is passed a mapping from A’s to sets of B’s, where ei- ther A’s are programs and B’s are schema components or vice-versa. • As for the previously described IntersectMeet-hash function, each B passed to the function via the mapping M is annotated with a “large random integer”. This integer should be large enough that the sum of the annotations for two typical sets of B’s will be equal only if the sets are equal.

• The findMinimals function, presented in pseudocode 5.8, is used to find the very smallest maximal pairs and the recurse function is used to add these to the output DAG R and find all more general maximal pairs if the A’s are program, or all more specific maximal pairs if the A’s are schema components.

• The recurse function takes a maximal set of B’s as Bmand a pair rpar

as the parent if any of the maximal pair containing Bm.

• The function first checks whether the pair containing Bmexists in the

DAG. If it has, the function simply adds an edge to rparfrom this pair

and exits.

• Otherwise, the maximal pair is new.

The function finds the respective maximal set of A’s, Am, for

5.5. ADDMEETS: GET MEETS FROM MAPPING 123

FUNCTION PromoteIncrement-hash(M ) // M is a mapping from A’s to sets of B’s A0= {a :< a → B >∈ M }

B0 = {b ∈ B :< a → B >∈ M }

FOR EACHb ∈ B0

SET FIELDbrandhash=large random integer

Set of pairs R = {}

FOR EACHBm ∈ findMinimals({}, B0)

recurse(Bm,null)

RETURN(R)

END

FUNCTION recurse(Bm, rpar)

// Bmis a set of B’s

// rparis a pair with a set of A’s and a set of B’s

IFfor some A0, < A0, Bm >∈ R

IFrparis non-null, put edge from < A0, Bm>to rparin DAG

ELSE

Am = ∩b∈Bm{a :< a → B

0 >∈ M, B0 ⊇ B m}

R = R ∪ < Am, Bm >

IFrparis non-null, put edge from < Am, Bm >to rpar in DAG

FOR EACHBm0 ∈findMinimals(Am, Bm)

recurse(Bm0 , < Am, Bm >).

END

It then adds an edge from the new pair to rparif any.

It then recurses on each maximal subset of Bm. These sets are

found using the findMinimals function.

Each such set is maximal, is a subset of Bm. Each set is also

minimally smaller, that is for each set B0

mof B’s found by getMin-

imals, there is no other maximal set of B’s which is both a subset of Bm and a superset of Bm0 .

The function findMinimals, used by PromoteIncrement-hash, is presented in pseudocode 5.8. The operation of the function is as follows:

FUNCTION findMinimals(A, B) // A is a set of A’s

// B is a set of B’s

FOR EACHa ∈ A0\A

SET FIELDahash =Pb∈B∩B0:<a→B0>∈Mbrandhash

MAKEA ∈ {{A}}ˆ as grouping of members of a ∈ A0\A by ahashvalue

Set of sets of B’s ˆB = {}

FOR EACHA0 ∈ ˆA

CHOOSEany a0 ∈ A0 ˆ

B = ˆB ∪ {B ∩ B0 :< a0→ B0>∈ M }

Remove each member Bmfrom ˆBwhere ∃Bn∈ ˆB : Bm ⊂ Bn

RETURNBˆ END

Pseudocode 5.8: findMinimals

• The function groups each a ∈ A0\Amby the subset of input set B to

which it maps in M .

As A is maximal and B has all B’s which are mapped to by all ele- ments of A, there could be no such a which maps to all of B. Instead,

5.5. ADDMEETS: GET MEETS FROM MAPPING 125 the set for any given a is the maximal set of B’s for A ∪ {a}.

• ˆAgroups possible a’s into those with different matched subsets of B.

• The construction of ˆB then explicitly finds each such subset of B.

• A final step removes members of ˆB which are subsets of some other member of ˆB.

Complexity

The main body of the recurse function executes exactly once for each max- imal pair for a total of R times. It finds Amfrom Bmat a cost of O(|A0||B0|).

It then calls findMinimals.

The findMinimals function gets the hash values for the members of A0\A at worst case complexity O(|A0||B0|). Done by a hash set, grouping

may be done in O(|A0|). Finding the maximal set of B’s for each mem-

ber of ˆAtakes O(|B0|) and thus constructing ˆB has worst case complexity

O(|A0||B0|). The step removing subsets from ˆBmay be done in O(|A0||B0|)

time by identifying the largest containing set in ˆB for each member of A0\A.

Thus the call to recurse has worst case complexity O(|A0||B0|) and the

call to PromoteIncrement-hash has worst case complexity O(|R||A0||B0|)

where there are |R| maximal pairs, there are |A0| A’s in M and there are

|B0| distinct B’s in the mapped-to sets of M . The main body of the recurse

function executes exactly once for each maximal pair for a total of R times. It finds Amfrom Bmat a cost of O(|A0||B0|). It then calls findMinimals.

The findMinimals function gets the hash values for the members of A0\A at worst case complexity O(|A0||B0|). Done by a hash set, grouping

may be done in O(|A0|). Finding the maximal set of B’s for each mem-

ber of ˆAtakes O(|B0|) and thus constructing ˆB has worst case complexity

time by identifying the largest containing set in ˆB for each member of A0\A.

Thus the call to recurse has worst case complexity O(|A0||B0|) and the

call to PromoteIncrement-hash has worst case complexity O(|R||A0||B0|)

where there are |R| maximal pairs, there are |A0| A’s in M and there are

|B0| distinct B’s in the mapped-to sets of M .

In document 0201LUAN E A M FOR IN INFORME ANUAL 2010 (página 95-100)