/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2013 Ausenco Engineering Canada Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
package com.jaamsim.ProbabilityDistributions;

import com.sandwell.JavaSimulation.DoubleInput;
import com.sandwell.JavaSimulation.Keyword;

/**
 * Log-Logistic Distribution.
 * Adapted from A.M. Law, "Simulation Modelling and Analysis, 4th Edition", page 456.
 */
public class LogLogisticDistribution extends Distribution {

	@Keyword(description = "The scale parameter for the Log-Logistic distribution.",
	         example = "LogLogisticDist-1 Scale { 3.0 }")
	private final DoubleInput scaleInput;

	@Keyword(description = "The shape parameter for the Log-Logistic distribution.  A decimal value > 0.0.",
	         example = "LogLogisticDist-1 Shape { 1.0 }")
	private final DoubleInput shapeInput;

	{
		scaleInput = new DoubleInput("Scale", "Key Inputs", 1.0d);
		scaleInput.setValidRange( 0.0, Double.POSITIVE_INFINITY);
		this.addInput(scaleInput, true);

		shapeInput = new DoubleInput("Shape", "Key Inputs", 1.0d);
		shapeInput.setValidRange( 2.000001d, Double.POSITIVE_INFINITY);
		this.addInput(shapeInput, true);
	}

	@Override
	protected double getNextSample() {

		// Inverse transform method
		double u = randomGenerator1.nextDouble();
		return scaleInput.getValue() * Math.pow( u / (1 - u), 1.0 / shapeInput.getValue() );
	}

	@Override
	protected double getMeanValue() {
		double theta = Math.PI / shapeInput.getValue();
		return scaleInput.getValue() * theta / Math.sin( theta );
	}

	@Override
	protected double getStandardDeviation() {
		double theta = Math.PI / shapeInput.getValue();
		return scaleInput.getValue() * Math.sqrt( theta * ( 2.0/Math.sin(2.0*theta) - theta/Math.pow( Math.sin(theta), 2.0) ) );
	}
}

@@ -657,42 +657,150 @@
 com.
-sandwell.JavaSimulation.DoubleInpu
+jaamsim.input.ValueInput;%0Aimport com.jaamsim.units.DimensionlessUnit;%0Aimport com.jaamsim.units.Unit;%0Aimport com.jaamsim.units.UserSpecifiedUni
 t;%0Ai
@@ -1172,37 +1172,36 @@
 %0A%09private final 
-Doubl
+Valu
 eInput scaleInpu
@@ -1380,21 +1380,20 @@
 e final 
-Doubl
+Valu
 eInput s
@@ -1418,37 +1418,36 @@
 caleInput = new 
-Doubl
+Valu
 eInput(%22Scale%22, 
@@ -1519,32 +1519,85 @@
 TIVE_INFINITY);%0A
+%09%09scaleInput.setUnitType( UserSpecifiedUnit.class );%0A
 %09%09this.addInput(
@@ -1635,21 +1635,20 @@
 t = new 
-Doubl
+Valu
 eInput(%22
@@ -1748,38 +1748,217 @@
 ;%0A%09%09
-this.addInput(shapeInput, true
+shapeInput.setUnitType( DimensionlessUnit.class );%0A%09%09this.addInput(shapeInput, true);%0A%09%7D%0A%0A%09@Override%0A%09protected void setUnitType(Class%3C? extends Unit%3E ut) %7B%0A%09%09super.setUnitType(ut);%0A%09%09scaleInput.setUnitType(ut
 );%0A%09

Add units to the LogLogisticDistribution