/*
 * 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.CalculationObjects;

import com.jaamsim.input.Keyword;
import com.sandwell.JavaSimulation.EntityListInput;
import com.sandwell.JavaSimulation.DoubleListInput;
import com.sandwell.JavaSimulation.InputErrorException;

/**
 * The WeightedSum object returns a weighted sum of its input values.
 * @author Harry King
 *
 */
public class WeightedSum extends DoubleCalculation {

	@Keyword(description = "The list of DoubleCalculations entities that are inputs to this calculation.",
	         example = "WeightedSum1 EntityList { Calc1  Calc2 }")
	private final EntityListInput<DoubleCalculation> entityListInput;

	@Keyword(description = "The list of multaplicative factors to be applied to the value provide by the inputs.",
	         example = "WeightedSum1 CoefficientList { 2.0  1.5 }")
	private final DoubleListInput coefficientListInput;

	{
		inputValue.setHidden(true);

		entityListInput = new EntityListInput<DoubleCalculation>( DoubleCalculation.class, "EntityList", "Key Inputs", null);
		this.addInput( entityListInput, true);

		coefficientListInput = new DoubleListInput( "CoefficientList", "Key Inputs", null);
		this.addInput( coefficientListInput, true);
	}

	@Override
	public void validate() {
		super.validate();

		// Confirm that the number of entries in the CoeffientList matches the EntityList
		if( coefficientListInput.getValue().size() != entityListInput.getValue().size() ) {
			throw new InputErrorException( "The number of entries for CoefficientList and EntityList must be equal" );
		}
	}

	@Override
	public void update(double simTime) {
		double val = 0.0;

		// Calculate the weighted sum
		for(int i=0; i<entityListInput.getValue().size(); i++ ) {
			val += coefficientListInput.getValue().get(i) * entityListInput.getValue().get(i).getValue();
		}

		// Set the present value
		this.setValue( val );
		return;
	}
}

@@ -1212,29 +1212,24 @@
 %3E entityList
-Input
 ;%0A%0A%09@Keyword
@@ -1442,21 +1442,16 @@
 ientList
-Input
 ;%0A%0A%09%7B%0A%09%09
@@ -1487,29 +1487,24 @@
 %09%09entityList
-Input
  = new Entit
@@ -1617,29 +1617,24 @@
 ( entityList
-Input
 , true);%0A%0A%09%09
@@ -1648,21 +1648,16 @@
 ientList
-Input
  = new D
@@ -1744,21 +1744,16 @@
 ientList
-Input
 , true);
@@ -1912,37 +1912,32 @@
  coefficientList
-Input
 .getValue().size
@@ -1944,37 +1944,32 @@
 () != entityList
-Input
 .getValue().size
@@ -2214,37 +2214,32 @@
 =0; i%3CentityList
-Input
 .getValue().size
@@ -2271,29 +2271,24 @@
 fficientList
-Input
 .getValue().
@@ -2306,21 +2306,16 @@
 tityList
-Input
 .getValu

Rename input objects for WeightedSum