Sample11_ServiceAgentsFromRawData.java
Created with JBuilder
import mads.core.*;
import java.util.*;

/**
 * <p><H1>Service Agents from Raw Data</H1></p>
 *
 * <p><B>Sample project no. 11 </B><BR\> </p>
 * In the previous tutorial we showed what one must do to implement a service agent in
 * MADS. Depending on the type of data or computation one has to encapsulate inside the
 * agent, one will design the <I>setServiceFunctionValues</I> accordingly.  <BR\>
 * <UL>
 *    <LI> The agent design is basically the same with the initially presented service agent
 *         All the action takes place in the <I>setServiceFunctionValues</I> function.<BR\>
 * </UL>
 * <p>This sample will show how one can create an agent starting with raw data. This data
 * is found in forecasts, usually in the form of Excel tables.  
 */

public class Sample11_ServiceAgentsFromRawData extends AServiceAgent
{
  // The name of the service
  public String getServiceName(){
    return "Gasoline price";
  }

  // The description, including the measurement unit
  public String getDescription(){
    return "Sample agent that returns the hi-price US gasoline forecast for 2000 - 2030, in USD/l";
  }

  // The time range, imposed by the data
  public String getTimeRange(){
    return "2000 - 2030";
  }

  // No parameters
  public String[] getParameters(){
    return new String[] {};
  }

  // The reference
  public String getReference(){
    return "EIA, Annual Energy Outlook 2006 with Projections to 2030, http://www.eia.doe.gov/oiaf/aeo/";
  }

  // No parameters, so nothing to do
  public String validateParameters(ArrayList parameterServiceFunctionsVector){
    return "";
  }

  // We now do the actual work. We first set the time interval this prediction is valid
  // and then, for each year, set the value.
  public void setServiceFunctionValues(ArrayList parameterServiceFunctionsVector, ServiceFunction myServiceFunction)
  {

    myServiceFunction.setBase(2000);
    myServiceFunction.setRange(30);

    myServiceFunction.setValue( 2000, 0.3590098176 );
    myServiceFunction.setValue( 2001, 0.329950892  );
    myServiceFunction.setValue( 2002, 0.3380081396 );
    myServiceFunction.setValue( 2003, 0.4358838845 );
    myServiceFunction.setValue( 2004, 0.5029835856 );
    myServiceFunction.setValue( 2005, 0.6102374384 );
    myServiceFunction.setValue( 2006, 0.618426772  );
    myServiceFunction.setValue( 2007, 0.6324278907 );
    myServiceFunction.setValue( 2008, 0.6345412671 );
    myServiceFunction.setValue( 2009, 0.6363904714 );
    myServiceFunction.setValue( 2010, 0.6266161055 );
    myServiceFunction.setValue( 2011, 0.6469573535 );
    myServiceFunction.setValue( 2012, 0.6641285368 );
    myServiceFunction.setValue( 2013, 0.6688836337 );
    myServiceFunction.setValue( 2014, 0.6871115053 );
    myServiceFunction.setValue( 2015, 0.7172271191 );
    myServiceFunction.setValue( 2016, 0.7188121514 );
    myServiceFunction.setValue( 2017, 0.7174912912 );
    myServiceFunction.setValue( 2018, 0.732284926  );
    myServiceFunction.setValue( 2019, 0.747606905  );
    myServiceFunction.setValue( 2020, 0.7560604107 );
    myServiceFunction.setValue( 2021, 0.7674198089 );
    myServiceFunction.setValue( 2022, 0.7655706045 );
    myServiceFunction.setValue( 2023, 0.7721749058 );
    myServiceFunction.setValue( 2024, 0.7581737871 );
    myServiceFunction.setValue( 2025, 0.7719107337 );
    myServiceFunction.setValue( 2026, 0.7787792071 );
    myServiceFunction.setValue( 2027, 0.7806284114 );
    myServiceFunction.setValue( 2028, 0.7896102612 );
    myServiceFunction.setValue( 2029, 0.7996487991 );
    myServiceFunction.setValue( 2030, 0.8059889283 );

   }
}



Sample11_ServiceAgentsFromRawData.java
Created with JBuilder