Package urban.transformers

Source Code of urban.transformers.AddRatesFromShapesTransformer

package urban.transformers;

import urban.model.Model;
import urban.model.Rule;
import urban.model.Statement;
import urban.model.info.ModelInfo;
import urban.shapes.RateCalculator;
import urban.shapes.ShapeParameters;

/**
* Uses shapes to calculate rates for bidirectional rules with rates that are zero.
*
* @see RateCalculator
*/
public class AddRatesFromShapesTransformer implements ModelTransformer {

  @Override
  public Model transform(Model in) {
    ShapeParameters sp = new ModelInfo(in.getLines()).getShapeParameters();
    RateCalculator rc = new RateCalculator(sp);
    Model out = new Model();
   
    for(Statement line : in.getLines())
      if (line instanceof Rule)
        out.addStatement(addRate(rc, (Rule)line));
      else
        out.addStatement(line);
   
    return out;
  }

  private Statement addRate(RateCalculator rc, Rule line) {
    if (!line.isBidirectional())
      return line;
   
    if (line.getForwardRate() != 0.0 || line.getBackwardRate() != 0.0)
      return line;
   
    return rc.calculateRates(new RuleToGeneratorTransformer().transform(line), line);
  }

}
TOP

Related Classes of urban.transformers.AddRatesFromShapesTransformer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.