9 A simple data
object that has a conditional capper/minimizer built in.
10 Simple but very useful in the context of multi-parameter scheduling.
14 Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
15 Copyright [2016-2024] EMBL-European Bioinformatics Institute
17 Licensed under the Apache License,
Version 2.0 (the
"License"); you may not use
this file except in compliance with the License.
18 You may obtain a copy of the License at
22 Unless required by applicable law or agreed to in writing, software distributed under the License
23 is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 See the License
for the specific language governing permissions and limitations under the License.
28 Please subscribe to the
Hive mailing list: http:
33 package Bio::EnsEMBL::Hive::Limiter;
39 my ($class, $description, $available_capacity) = @_;
41 my $self = bless {}, $class;
42 $self->description( $description );
44 $self->original_capacity( $available_capacity );
45 $self->available_capacity( $available_capacity );
47 # we fix the multiplier at 1 for direct limiters, but expect it to be (re)set later by reciprocal limiters:
48 $self->multiplier( 1 );
58 $self->{_description} = shift @_;
60 return $self->{_description};
64 sub original_capacity {
68 $self->{_original_capacity} = shift @_;
70 return $self->{_original_capacity};
74 sub available_capacity {
78 $self->{_available_capacity} = shift @_;
80 return $self->{_available_capacity};
88 $self->{_multiplier} = shift @_;
90 return $self->{_multiplier};
97 return defined($self->available_capacity) && ($self->available_capacity <= 0.0);
101 sub preliminary_offer {
102 my ($self, $slots_asked) = @_;
104 my $available_capacity = $self->available_capacity;
105 my $multiplier = $self->multiplier;
107 if( defined($available_capacity) and defined($multiplier) and ($multiplier >= 0.0) ) { #
if multiplier is negative it is not limiting
109 $available_capacity = 0
if($available_capacity<0);
111 my $product = $available_capacity * $multiplier;
112 my $slots_available = int(
"$product" ); # stringification helps to round up things like 0.1*10 (instead of leaving them at 0.99999999)
114 my $hit_the_limit = $slots_available<$slots_asked;
116 return ($hit_the_limit ? $slots_available : $slots_asked , $hit_the_limit);
119 return ($slots_asked, 0);
124 my ($self, $slots_agreed) = @_;
126 my $available_capacity = $self->available_capacity;
127 my $multiplier = $self->multiplier;
129 if( defined($available_capacity) and defined($multiplier) and ($multiplier > 0.0) ) { #
if multiplier is not positive capacity stays unaffected
130 # and we should not arrive here if $multiplier==0
132 $self->available_capacity( $available_capacity - $slots_agreed/$multiplier );