All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.chen0040.gp.lgp.program.Register Maven / Gradle / Ivy

There is a newer version: 1.0.14
Show newest version
package com.github.chen0040.gp.lgp.program;


import com.github.chen0040.gp.commons.Indexable;
import com.github.chen0040.gp.services.RandEngine;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;


/**
 * Created by xschen on 27/4/2017.
 * This class represents a register in a linear program
 *
 * 
    *
  1. a register can be read-only, in which case it is a constant
  2. *
  3. a register is continuous numeric variable in a linear program
  4. *
*/ @Getter @Setter public class Register implements Serializable, Indexable { private static final long serialVersionUID = 8423690373685553734L; // denote whether the register is read-only private boolean constant; // value stored in the register private double value; // the index of the register within the linear program private int index; public Register makeCopy(){ Register clone = new Register(); clone.setConstant(constant); clone.setValue(value); clone.setIndex(index); return clone; } @Override public String getName() { return (constant ? "c" : "r") + "[" + index + "]"; } public void mutate(RandEngine randomEngine, double sd){ value += randomEngine.normal(0, 1.0) * sd; } @Override public String toString(){ return getName(); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Register register = (Register) o; if (constant != register.constant) return false; if (Double.compare(register.value, value) != 0) return false; return index == register.index; } @Override public int hashCode() { int result; long temp; result = (constant ? 1 : 0); temp = Double.doubleToLongBits(value); result = 31 * result + (int) (temp ^ (temp >>> 32)); result = 31 * result + index; return result; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy