Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. package org.moeaframework.util.tree;
  2.  
  3. import java.math.RoundingMode;
  4. import java.text.DecimalFormat;
  5. import java.util.Random;
  6.  
  7. public class Lesser_than_threshold extends Threshold {
  8.     public Lesser_than_threshold(String name, Double min, Double max, Double val,int type) {
  9.         super(name, min, max, val,type);
  10.    
  11.     }
  12.  
  13.     @Override
  14.     public Node copyNode() {
  15.         return new Lesser_than_threshold(name,min_val,max_val,val,type) ;
  16.     }
  17.  
  18.     @Override
  19.     public Boolean evaluate(Environment environment) {
  20.         if (this.val == -1)
  21.         {
  22.             if (type == 1 )
  23.             {
  24.                 //System.out.println("here!") ;
  25.                 // Continuous variable
  26.                 this.val = this.min_val + Math.random()*(this.max_val - this.min_val) ;
  27.             }
  28.             else
  29.             {
  30.                 Random randomno = new Random();
  31.                 this.val = (double) randomno.nextInt(this.max_val.intValue()+1) + this.min_val ;
  32.             }
  33.         }
  34.         Double value = environment.get(Double.class, this.name) ;
  35.         //System.out.println(this.toString()) ;
  36.         return (value <= this.val.doubleValue()) ;
  37.     }
  38.     @Override
  39.     public String toString()
  40.     {
  41.         DecimalFormat df = new DecimalFormat("#.##");
  42.         df.setRoundingMode(RoundingMode.CEILING);
  43.         return name + " <= " + df.format(this.val);
  44.        
  45.     }
  46.     @Override
  47.     public String getName()
  48.     {
  49.         return this.toString() ;
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement