All Frameworks  Class Hierarchy  This Framework  Next  Indexes

OptimizationInterfaces Class CATOptAlgorithmAdapter

System.IUnknown
  |
  +---System.IDispatch
    |
    +---System.CATBaseUnknown
      |
      +---System.CATEventSubscriber
        |
        +---CATOptAlgorithmAdapter
 

Usage: you can derive this class.


public class CATOptAlgorithmAdapter

CAA Adapter to CATIOptAlgorithm Interface.
Role: This class should be derived to implement features extension to CATIOptAlgorithm.
CATIOptAlgorithm is the interface used by the product PEO to indentify and use the new algorithms.


Constructor and Destructor Index


o CATOptAlgorithmAdapter()
o ~CATOptAlgorithmAdapter()

Method Index


o AfterLastUpdate()
Allows to restore the settings impacted by the BeforeFirstUpdate() method.
o AllHistoricToString()
Returns a string describing the history of the optimization algorithm.
o BeforeFirstUpdate()
Initializes Settings.
o BeforeLastUpdate()
Allows to restore the visualization settings for the last update.
o GetBestResultIndex(int&)
Returns the index of the Opimization Log corresponding to the best solution found according to the problem defined.
o GetEndIterationNotification()
Retrieves the event send when an iteration of the algorithm is done.
o GetSetting(char*,double&)
Gets an algorithm setting.
o InitUpdate(CATIOptOptimization_var&,CATLISTV(CATBaseUnknown_var)*,CATLISTV(CATBaseUnknown_var)*)
Initializes the update management engine.
o LaunchUpdate()
Asks the update management engine to launch the update of the inputs/outputs.
o OneHistoricToString(int)
o Run(CATIOptOptimization_var&)
Triggers the computation of the user algorithm.
o SendEndIterationNotification(CATNotification*)
Sends the end of iteration notification.
o SetSetting(char*,double)
Sets an algorithm setting.

Constructor and Destructor


o CATOptAlgorithmAdapter
public CATOptAlgorithmAdapter()
o ~CATOptAlgorithmAdapter
public virtual ~CATOptAlgorithmAdapter()

Methods


o AfterLastUpdate
protected HRESULT AfterLastUpdate()
Allows to restore the settings impacted by the BeforeFirstUpdate() method. BeforeFirstUpdate(). It has to be called one time, after running the last update.
Returns:
E_FAIL if something fails (update management engine not initialized...).
o AllHistoricToString
public virtual CATUnicodeString AllHistoricToString()
Returns a string describing the history of the optimization algorithm.
Returns:
The string containing the evolution of the free parameters, objective and constraints. Contains additional information with respect to the design table output of the optimization.
o BeforeFirstUpdate
protected HRESULT BeforeFirstUpdate()
Initializes Settings. This method modifies some settings (measure) to assure that the model will be correctly updated according to the given optimization settings (visu/no visu). It has to be called one time : - after the InitUpdate method - before calling the LaunchUpdate() method for the first time.
Returns:
E_FAIL if something fails (update management engine not initialized...).
o BeforeLastUpdate
protected HRESULT BeforeLastUpdate()
Allows to restore the visualization settings for the last update. It has to be called one time, before running the last update.
Returns:
E_FAIL if something fails (update management engine not initialized...).
o GetBestResultIndex
public HRESULT GetBestResultIndex(int& oBestResultIndex)
Returns the index of the Opimization Log corresponding to the best solution found according to the problem defined.
Parameters:
oBestResultIndex
The index of the best point found by the optimizer.
Returns:
S_OK if the best is found. E_FAIL if it was not found. E_NOTIMPLEMENTED for algorithms (such as DOEs) for which this notion is meaningless.
o GetEndIterationNotification
public CATCallbackEvent GetEndIterationNotification()const
Retrieves the event send when an iteration of the algorithm is done. If you use the SendEndIterationNotification() method after each iteration, this event is triggered when the algorithm has finished an iteration (each iteration corresponds to a model update)

In your dialog, put a callback on this method to receive the end iteration notification.

o GetSetting
public HRESULT GetSetting( const char* iAttrName,
double& oContent)
Gets an algorithm setting. The setting is defined by its attribute name. For pre-requisites restriction constraints, you have to overload it in derived classes.
Example:
 Here is the code you have to write in your derived class
 {
	CATISpecAttrAccess_var access = this;
	if (!access)
		return E_FAIL;	

	CATISpecAttrKey_var key = access->GetAttrKey(attrName);
	if (!key)
		return E_FAIL;

	key->Release();

	CATAttrKind type = key->GetType();
	if (type == tk_integer)
		content = (double) access->GetInteger(key);
	else if (type == tk_double)
		content = access->GetDouble(key);
	else
		return E_FAIL;

	return S_OK;
 }
 
Parameters:
iAttrName
The name of the settings attribute to get.
oContent
The returned value of the setting. it is given as a double but can be an integer.
Returns:
S_OK if the operation succeeded, E_FAIL else (non existing attribute)
o InitUpdate
protected HRESULT InitUpdate( const CATIOptOptimization_var& iOptim,
const CATLISTV(CATBaseUnknown_var)* iInputs,
const CATLISTV(CATBaseUnknown_var)* iOutputs)
Initializes the update management engine. It has to be called (at least) one time , before running the others ( LaunchUpdate, BeforeFirstUpdate, BeforeLastUpdate and AfterLastUpdate) else each one of those methods will do nothing but returning E_FAIL !
Parameters:
iOptim
the optimization whose settings have to be used during the update (like Visu/No Visu). In most cases, it is the optimization linked to the algorithm.
iInputs
The inputs that have to be updated (in most cases, they are the given optimization free parameters, but they may be different).
iOutputs
The outputs that have to be updated (in most cases, they are the given optimization goals, but they may be different). Return E_FAIL if something fails.
o LaunchUpdate
protected HRESULT LaunchUpdate()
Asks the update management engine to launch the update of the inputs/outputs. This update is given in the InitUpdate method, according to the settings of the given optimization.
Returns:
E_FAIL if something fails (update management engine not initialized...).
o OneHistoricToString
public virtual CATUnicodeString OneHistoricToString(int iHistoricIndex)
Parameters:
oBestResultIndex
The index of the historic to be dumped. Returns a string describing the history of the optimization algorithm.
Returns:
The string containing the evolution of the free parameters, objective and constraints. Contains additional information with respect to the design table output of the optimization.
o Run
public virtual HRESULT Run(CATIOptOptimization_var& spiOptim) = 0
Triggers the computation of the user algorithm. Role: This method must be overloaded in derived classes. Write your algorithm code here. It may be a loop of the following type : while the termination criteria are not reached, do a modification of the inputs values, update the outputs and check the termination criteria. To do that, you will have to call the protected methods of this class in the following order :
 InitUpdate()
 BeforeFirstUpdate()

 While (...)
 {
		If("it is the last update")
			BeforeLastUpdate()

		LaunchUpdate()		
 }

 AfterLastUpdate()
 
Parameters:
spiOptim
The optimization linked to this algorithm. It is used to access the update engine used in the
InitUpdate() and LaunchUpdate() methods. In most cases the algorithm is working on its optimization free parameters and goals, so that the optimization may be used to get the inputs and outputs to update.
Returns:
S_OK if the operation succeeded, E_FAIL else
o SendEndIterationNotification
protected virtual HRESULT SendEndIterationNotification(CATNotification* iNotif)
Sends the end of iteration notification. It can be caugth everywhere you want (for example, in the stop dialog in order to update it during the run).
Parameters:
The
notification you want to send.
Returns:
S_OK if the operation succeeded, E_FAIL else.
o SetSetting
public HRESULT SetSetting( const char* iAttrName,
double iContent)
Sets an algorithm setting. This setting is defined by its attribute name. For pre-requisites restriction constraints, you have to overload it in derived classes.
Example:
 Here is the code you have to write in your derived class --
 {	
	CATISpecAttrAccess_var access = this;
	if (!access)
		return E_FAIL;

	CATISpecAttrKey_var key = access->GetAttrKey(attrName);
	if (!key)
		return E_FAIL;

	key->Release();
	
	CATAttrKind type = key->GetType();
	if (type == tk_integer)
		access->SetInteger(key, (int)content);
	else if (type == tk_double)
		access->SetDouble(key, content);
	else
		return E_FAIL;

	return S_OK;
 }
 
Parameters:
iAttrName
The name of the settings attribute to set.
iContent
The value of the setting to set. it is given as a double but can be an integer.
Returns:
S_OK if the operation succeeded, E_FAIL else (non existing attribute)

This object is included in the file: CATOptAlgorithmAdapter.h
If needed, your Imakefile.mk should include the module: OptimizationItf

Copyright © 2003, Dassault Systèmes. All rights reserved.