Commit 8580b9e9 authored by snuverink_j's avatar snuverink_j

remove MATCH actions

parent 7d535990
......@@ -78,7 +78,6 @@ add_subdirectory (Distribution)
add_subdirectory (Elements)
add_subdirectory (Expressions)
add_subdirectory (Lines)
add_subdirectory (Match)
add_subdirectory (OpalConfigure)
add_subdirectory (OpalParser)
add_subdirectory (Optimize)
......
// ------------------------------------------------------------------------
// $RCSfile: AbstractFun.cpp,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: AbstractFun
// This class is the abstract base for a single function to be adjusted
// to zero during matching.
//
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:33:43 $
// $Author: Andreas Adelmann $
//
// ------------------------------------------------------------------------
#include "Match/AbstractFun.h"
// Class AbstractFun
// ------------------------------------------------------------------------
AbstractFun::AbstractFun()
{}
AbstractFun::~AbstractFun()
{}
#ifndef OPAL_AbstractFun_HH
#define OPAL_AbstractFun_HH 1
// ------------------------------------------------------------------------
// $RCSfile: AbstractFun.h,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: AbstractFun
//
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:33:43 $
// $Author: Andreas Adelmann $
//
// ------------------------------------------------------------------------
#include "Algebra/Vector.h"
#include <iosfwd>
#include <string>
// Class AbstractFun
// ------------------------------------------------------------------------
/// Abstract base for matching constraints.
// The interface allows a constraint to return several constrained
// functions.
class AbstractFun {
public:
AbstractFun();
virtual ~AbstractFun();
/// Get number of constrained values.
virtual int countConstraints() const = 0;
/// Evaluate the matching function(s).
// Increment [b]n[/b] for each constrained value and store the value
// in vector [b]f[/b].
virtual void evaluate(Vector<double> &f, int &n) const = 0;
/// Print the function name and value(s).
virtual void print(std::ostream &) const = 0;
private:
// Not implemented.
AbstractFun(const AbstractFun &);
void operator=(const AbstractFun &);
};
#endif // OPAL_AbstractFun_HH
// ------------------------------------------------------------------------
// $RCSfile: AbstractVar.cpp,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: AbstractVar
// This abstract class defines the interface for a variable to be
// adjusted during matching.
//
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:33:43 $
// $Author: Andreas Adelmann $
//
// ------------------------------------------------------------------------
#include "Match/AbstractVar.h"
// Class AbstractVar
// ------------------------------------------------------------------------
AbstractVar::AbstractVar(const std::string &name):
itsName(name)
{}
AbstractVar::~AbstractVar()
{}
const std::string &AbstractVar::getName() const {
return itsName;
}
#ifndef OPAL_AbstractVar_HH
#define OPAL_AbstractVar_HH 1
// ------------------------------------------------------------------------
// $RCSfile: AbstractVar.h,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: AbstractVar
//
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:33:43 $
// $Author: Andreas Adelmann $
//
// ------------------------------------------------------------------------
#include <iosfwd>
#include <string>
// Class AbstractVar
// ------------------------------------------------------------------------
/// Abstract base for a matching variable.
// The interface allows for variable transformations used to implement
// upper and/or lower limits for the values.
class AbstractVar {
public:
/// Constructor.
// Assign the variable name.
AbstractVar(const std::string &name);
virtual ~AbstractVar();
/// Get the variable name.
virtual const std::string &getName() const;
/// Get the current internal parameter value.
virtual double getInternalValue() const = 0;
/// Set the current internal parameter value.
virtual void setInternalValue(double) = 0;
/// Get the current external parameter value.
virtual double getExternalValue() const = 0;
/// Set the current external parameter value.
virtual void setExternalValue(double) = 0;
/// Print the variable name and value.
virtual void print(std::ostream &) const = 0;
protected:
/// Name of the variable.
const std::string itsName;
private:
// Not implemented.
AbstractVar();
AbstractVar(const AbstractVar &);
void operator=(const AbstractVar &);
};
#endif // OPAL_AbstractVar_HH
set (_SRCS
AbstractFun.cpp
AbstractVar.cpp
ConcreteFun.cpp
ConcreteVar.cpp
ConstraintCmd.cpp
LMDif.cpp
Match.cpp
MatchCmd.cpp
MatchEnd.cpp
MatchOption.cpp
MatchParser.cpp
Migrad.cpp
Simplex.cpp
VaryCmd.cpp
)
include_directories (
${CMAKE_CURRENT_SOURCE_DIR}
)
add_opal_sources(${_SRCS})
set (HDRS
AbstractFun.h
AbstractVar.h
ConcreteFun.h
ConcreteVar.h
ConstraintCmd.h
LMDif.h
MatchCmd.h
MatchEnd.h
Match.h
MatchLimits.h
MatchOption.h
MatchParser.h
MatchState.h
Migrad.h
Simplex.h
VaryCmd.h
)
install (FILES ${HDRS} DESTINATION "${CMAKE_INSTALL_PREFIX}/include/Match")
# vi: set et ts=4 sw=4 sts=4:
# Local Variables:
# mode: cmake
# cmake-tab-width: 4
# indent-tabs-mode: nil
# require-final-newline: nil
# End:
// ------------------------------------------------------------------------
// $RCSfile: ConcreteFun.cpp,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: ConcreteFun
// This class is the concrete class for a single constrained value
// for matching.
//
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:33:43 $
// $Author: Andreas Adelmann $
//
// ------------------------------------------------------------------------
#include "Match/ConcreteFun.h"
#include "Attributes/Attributes.h"
#include "Utilities/LogicalError.h"
#include <iomanip>
#include <iostream>
// Character form of relational operators.
static const char *relString[] = { " == ", " > ", " < " };
// Class ConcreteFun
// ------------------------------------------------------------------------
ConcreteFun::ConcreteFun
(Attribute &lhs, int rel, Attribute &rhs, Attribute &wgt):
itsLhs(lhs),
itsRhs(rhs),
relation(rel),
itsWeight(Attributes::getRealArray(wgt))
{}
ConcreteFun::~ConcreteFun()
{}
int ConcreteFun::countConstraints() const {
return itsWeight.size();
}
void ConcreteFun::evaluate(Vector<double> &fun, int &index) const {
lValue = Attributes::getRealArray(itsLhs);
rValue = Attributes::getRealArray(itsRhs);
std::vector<double>::size_type size = itsWeight.size();
if(lValue.size() != size || rValue.size() != size) {
throw LogicalError("ConcreteFun::evaluate()",
"Matching constraint is inconsistent, size_of(LHS), "
"size_of(RHS), size_of(WGT) should all be equal.");
}
value.erase(value.begin(), value.end());
value.resize(size, 0.0);
for(std::vector<double>::size_type i = 0; i < size; ++i) {
switch(relation) {
case 0:
value[i] = lValue[i] - rValue[i];
break;
case 1:
if(lValue[i] < rValue[i]) value[i] = lValue[i] - rValue[i];
break;
case 2:
if(lValue[i] > rValue[i]) value[i] = lValue[i] - rValue[i];
}
fun[index++] = value[i] * itsWeight[i];
}
}
void ConcreteFun::print(std::ostream &os) const {
// Print the symbolic representation of the constraint.
os << "\nCondition: " << itsLhs << relString[relation] << itsRhs
<< std::endl;
// Print the value(s) of the constraint.
std::streamsize old_prec = os.precision(9);
os.setf(std::ios::scientific, std::ios::floatfield);
for(std::vector<double>::size_type i = 0; i < lValue.size(); ++i) {
os << " lhs = " << std::setw(16) << lValue[i]
<< ", rhs = " << std::setw(16) << rValue[i]
<< ", wgt = " << std::setw(16) << itsWeight[i]
<< ", val = " << std::setw(16) << value[i]
<< std::endl;
}
os.setf(std::ios::fixed, std::ios::floatfield);
os.precision(old_prec);
}
#ifndef OPAL_ConcreteFun_HH
#define OPAL_ConcreteFun_HH 1
// ------------------------------------------------------------------------
// $RCSfile: ConcreteFun.h,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: ConcreteFun
//
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:33:43 $
// $Author: Andreas Adelmann $
//
// ------------------------------------------------------------------------
#include "Match/AbstractFun.h"
#include "AbstractObjects/Attribute.h"
#include <vector>
// Class ConcreteFun
// ------------------------------------------------------------------------
/// A single matching constraints or an array of matching constraints.
// The left and right hand sides and the weights of the constraint are
// all given by array expressions.
class ConcreteFun: public AbstractFun {
public:
/// Constructor.
// Uses the following arguments:
// [ol]
// [li] The left-hand side(s) for the constraint.
// [li] A code for the type of constraint.
// [li] The right-hand side(s) for the constraint.
// [li] The weight(s) for the constraint.
// [/ol]
ConcreteFun(Attribute &lhs, int rel, Attribute &rhs, Attribute &wgt);
virtual ~ConcreteFun();
/// Get the number of constrained values.
virtual int countConstraints() const;
/// Evaluate the matching function(s).
// Increment [b]n[/b] for each constrained value and store the value
// in vector [b]f[/b].
virtual void evaluate(Vector<double> &f, int &) const;
/// Print the function name and value(s).
virtual void print(std::ostream &) const;
private:
// Not implemented.
ConcreteFun();
ConcreteFun(const ConcreteFun &);
void operator=(const ConcreteFun &);
// The constraint expression to be adjusted and its weight.
Attribute itsLhs;
Attribute itsRhs;
int relation;
std::vector<double> itsWeight;
// The value cache.
mutable std::vector<double> lValue;
mutable std::vector<double> rValue;
mutable std::vector<double> value;
};
#endif // OPAL_ConcreteFun_HH
// ------------------------------------------------------------------------
// $RCSfile: ConcreteVar.cpp,v $
// ------------------------------------------------------------------------
// $Revision: 1.5 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: ConcreteVar
// This class is the concrete class for a single variable to be varied
// during matching. It implements the setting and retrieving of the
// value in the system to be adjusted.
//
// JMJ 7/4/2000: changed to make output from MATCH like OPAL input.
//
// ------------------------------------------------------------------------
//
// $Date: 2002/03/28 21:27:54 $
// $Author: jsberg $
//
// ------------------------------------------------------------------------
#include "Match/ConcreteVar.h"
#include "AbstractObjects/OpalData.h"
#include "Attributes/Attributes.h"
#include <cmath>
#include <iomanip>
#include <iostream>
#include <algorithm>
// Class ConcreteVar
// ------------------------------------------------------------------------
ConcreteVar::ConcreteVar
(const std::string &name, Attribute &attr, int limits, double pars[4]):
AbstractVar(name),
itsAttr(attr),
itsStep(std::abs(pars[1])),
itsLimits(limits),
itsMin(pars[2]),
itsMax(pars[3]) {
// Builtin constant.
const double stplim = 0.2;
// Convert the step sizes.
switch(limits) {
case UPPER_LIMIT:
case LOWER_LIMIT:
if(pars[0] != 0.0) itsStep /= pars[0];
break;
case BOTH_LIMITS:
itsStep /= sqrt(pars[0] * (pars[0] - itsMin - itsMax) + itsMin * itsMax);
break;
default:
break;
}
// Bring the step in range.
if(itsStep > stplim) itsStep = stplim;
}
ConcreteVar::~ConcreteVar()
{}
double ConcreteVar::getInternalValue() const {
double value = Attributes::getReal(itsAttr);
switch(itsLimits) {
case LOWER_LIMIT:
if(value < itsMin) value = itsMin;
return sqrt(value - itsMin);
case UPPER_LIMIT:
if(value > itsMax) value = itsMax;
return sqrt(itsMax - value);
case BOTH_LIMITS:
if(value < itsMin) value = itsMin;
if(value > itsMax) value = itsMax;
return asin((value + value - itsMin - itsMax) / (itsMax - itsMin));
default:
return value;
}
}
void ConcreteVar::setInternalValue(double value) {
// Store internal value to chache.
switch(itsLimits) {
case LOWER_LIMIT:
value = itsMin + value * value;
break;
case UPPER_LIMIT:
value = itsMax - value * value;
break;
case BOTH_LIMITS:
value = ((itsMin + itsMax) + (itsMax - itsMin) * sin(value)) / 2.0;
break;
default:
break;
}
// Transmit to data structure.
setExternalValue(value);
}
double ConcreteVar::getExternalValue() const {
return Attributes::getReal(itsAttr);
}
void ConcreteVar::setExternalValue(double value) {
// Transmit external value to cache and to data structure.
Attributes::setReal(itsAttr, value);
OpalData::getInstance()->makeDirty(0);
}
void ConcreteVar::print(std::ostream &os) const {
std::streamsize old_prec = os.precision(10);
os << itsName << " := "
<< std::setw(16) << getExternalValue() << ";" << std::endl;
os.precision(old_prec);
}
// Above changed by JMJ, 7/4/2000, increased precision to 10, swapped columns
// and slipped in the ":=".
// Doesn't seem to be happening in version of July 2000 ??
#ifndef OPAL_ConcreteVar_HH
#define OPAL_ConcreteVar_HH 1
// ------------------------------------------------------------------------
// $RCSfile: ConcreteVar.h,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: ConcreteVar
//
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:33:43 $
// $Author: Andreas Adelmann $
//
// ------------------------------------------------------------------------
#include "Match/AbstractVar.h"
#include "AbstractObjects/Attribute.h"
#include "Match/MatchLimits.h"
// Class ConcreteVar
// ------------------------------------------------------------------------
/// Concrete class for a matching variable.
// Implements the setting and retrieving of the value in the system
// to be adjusted. Upper and lower limits are implemented by variable
// transformations which map the infinite range to the limited range.
class ConcreteVar: public AbstractVar {
public:
/// Constructor.
// Uses the following arguments:
// [ol]
// [li] The variable name.
// [li] An attribute containing a reference to thevalue to be adjusted.
// [li] A code for limit values: 0=no limit, 1=lower, 2=upper, 3=both.
// [li] Value, lower, upper, and step.
// [/ol]
ConcreteVar(const std::string &name, Attribute &data,
int limits, double pars[4]);
virtual ~ConcreteVar();
/// Get the current internal parameter value.
// The internal value is unlimited, it maps to the external value
// so as to keep the latter constrained.
virtual double getInternalValue() const;
/// Set the current internal parameter value.
// The internal value is unlimited, it maps to the external value
// so as to keep the latter constrained.
virtual void setInternalValue(double);
/// Get the current external parameter value.
// The external value should be consistent with the given limits.
virtual double getExternalValue() const;
/// Set the current external parameter value.
// The external value should be consistent with the given limits.
virtual void setExternalValue(double);
/// Print the variable name and value.
virtual void print(std::ostream &) const;
private:
// Not implemented.
ConcreteVar();
ConcreteVar(const ConcreteVar &);
void operator=(const ConcreteVar &);
// The attribute to be manipulated.
Attribute itsAttr;
// The current internal parameter step.
double itsStep;
// The fixed parameter limits.
int itsLimits;
double itsMin;
double itsMax;
};
#endif // OPAL_ConcreteVar_HH
// ------------------------------------------------------------------------
// $RCSfile: ConstraintCmd.cpp,v $
// ------------------------------------------------------------------------
// $Revision: 1.2 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: ConstraintCmd
// The class for the OPAL CONSTRAINT command.
//
// ------------------------------------------------------------------------
//
// $Date: 2001/08/13 15:10:01 $
// $Author: jowett $
//
// ------------------------------------------------------------------------
#include "Match/ConstraintCmd.h"
#include "Attributes/Attributes.h"
#include "AbstractObjects/Expressions.h"
#include "Match/ConcreteFun.h"
#include "Match/Match.h"
#include "Parser/Statement.h"