File: SitePerForet.pm

package info (click to toggle)
altree 1.3.1-10
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 11,044 kB
  • sloc: perl: 3,482; ansic: 1,716; sh: 187; pascal: 66; makefile: 11
file content (149 lines) | stat: -rw-r--r-- 3,569 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package ALTree::SitePerForet;

################################################################
################################################################
####################### SitePerForet  ##########################
################################################################
################################################################

use base qw(ALTree::Base ALTree::Site);

sub New { # [classe] site_nb
    my $class=shift;
    my $self={};
    my $site_nb=shift;
    bless($self, $class);
    $self->InitSite($site_nb);
    $self->_init("nb_mut" => 0, @_);
    return $self;
}

sub NewSens {
    my $self=shift;
    my $sens=shift;
    return ALTree::SiteSensPerForet->New($sens, $self);
}

sub mysort {
    my $func=shift;
    my @tab=@_;

    my @tab2=();

    if (scalar(@tab) == 0) {
	return @tab2;
    }
 #   print "Site ", $tab[0]->GetSiteNb(), "\n";
#    foreach my $sens (@tab) {
#	print $sens->GetVi()," ", $sens->GetSensLabel(), "\n";
#    }
    my $size;
    while (($size=scalar(@tab)) > 1) {
	my $min=0;
	for(my $i=1; $i<$size; $i++) {
	    if ($func->($tab[$i], $tab[$min]) < 0) {
		$min=$i;
	    }
	}
	push @tab2, $tab[$min];
#	print "min=$min adding ",$tab[$min]->GetSensLabel(),"\n";
#	print "Old tab\n";
#	foreach my $sens (@tab) {
#	    print $sens->GetVi()," ", $sens->GetSensLabel(), "\n";
#	}
	#my @tab3=splice(@tab, $min, 1);
	my @tab3;
	for (my $i=0; $i<=$#tab; $i++) {
	    if ($i != $min) {
		push @tab3, $tab[$i];
	    }
	}
#	print "NewTab\n";
#	foreach my $sens (@tab3) {
#	    print $sens->GetVi()," ", $sens->GetSensLabel(), "\n";
#	}
	@tab=@tab3;
    }
    push @tab2, $tab[0];
#    print "Site ", $tab[0]->GetSiteNb(), " result\n";
#    foreach my $sens (@tab2) {
#	print $sens->GetVi()," ", $sens->GetSensLabel(), "\n";
#    }
    return @tab2;

}

sub functrie {
    my $a=shift;
    my $b=shift;
    #print "a=$a, b=$b\n";
    #if (not defined($a)) {
	#return 0;
	#print "a=$a b=$b\n";
	#die "beauk\n";
    #}
   # my $value=($b->GetVi() <=> $a->GetVi());
   # print "Comparing ", $b->GetVi(), " and ", $a->GetVi(), " = $value\n";
   # return $value;#
    return ($b->GetVi() <=> $a->GetVi());
}

sub _EnsureViMax {
    my($self)=shift;
    if (not exists ($self->{"V_i_max"})) {
	my @toto=$self->GetSensList();
	#print "site: ", $self->GetSiteNb(), "\n";
	#for my $ref (@toto) {
	    #print "Ref: $ref\n";
	#}
	my @tab_trie=mysort \&functrie, @toto;
	#for my $ref (@toto) {
	    #print "Ref: $ref\n";
	#}

	#my @tab3;
	#for (my $i=0; $i<=$#toto; $i++) {
	#    print "value $i = $toto[$i]\n";
	#    push @tab3, $toto[$i];
	#}

	#my @tab_trie=sort {
	#    $b->GetVi() <=> $a->GetVi();
	#} @tab3;
	
	my($Vimax)=$self->{"V_i_max"}=$tab_trie[0]->GetVi();
	for (my $i=1; $i<=$#tab_trie; $i++) {
	    if ($tab_trie[$i]->GetVi() !=  $Vimax) {
		splice(@tab_trie, $i); # Elimine tout  partir de indice $i
		last;
	    }
	}
	#print "Vi max : ", $Vimax, "\n";
	$self->{"V_i_max_tab"}=\@tab_trie;
    }
}
sub GetViMax {
    my $self=shift;
    $self->_EnsureViMax();
    return $self->{"V_i_max"};
}   
sub GetViMaxSens {
    my($self)=shift;
    my($index)=shift;
    $self->_EnsureViMax();
    return $self->{"V_i_max_tab"}->[$index];
}
#NbViMaxSens() => nombre sitesensperforet
sub NbViMaxSens {
    my($self)=shift; 
    $self->_EnsureViMax();
    return (scalar @{$self->{"V_i_max_tab"}});
}
#GetViMaxSensList() => array de tous les sitessensperforet (avec Vi==ViMax)
sub GetViMaxSensList {
    my($self)=shift; 
    $self->_EnsureViMax();
    return @{$self->{"V_i_max_tab"}}; # Comment a marche ce truc?
}
 
1;