use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.
the class Binpack method binPackSystem.
protected AssignmentResult binPackSystem(final SystemInstance root, Expansor expansor, LowLevelBinPacker packer, final AnalysisErrorReporterManager errManager, final SystemOperationMode som) {
existsProcessorWithMIPS = false;
existsProcessorWithoutMIPS = false;
existsThreadWithReferenceProcessor = false;
existsThreadWithoutReferenceProcessor = false;
/*
* Map from AADL ComponentInstances representing threads to
* the bin packing SoftwareNode that models the thread.
*/
final Map<ComponentInstance, AADLThread> threadToSoftwareNode = new HashMap<>();
/*
* Set of thread components. This is is the keySet of
* threadToSoftwareNode.
*/
final Set<ComponentInstance> threads = threadToSoftwareNode.keySet();
/*
* Map from AADL ComponentInstances representing threads to
* the set of AADL ComponentInstances that cannot be collocated
* with it.
*/
final Map<ComponentInstance, Set<ComponentInstance>> notCollocated = new HashMap<>();
/*
* Map from AADL ComponentInstance representing processors to
* the bin packing Processor that models them.
*/
final Map<ComponentInstance, AADLProcessor> procToHardware = new HashMap<>();
/*
* Map from AADL BusInstance representing Buses to
* The bin packing Link that models them.
*/
final Map<ComponentInstance, AADLBus> busToHardware = new HashMap<>();
/*
* One site to rule them all! We don't care about the site
* architecture, so just create one site to hold everything.
* We aren't worried about power or space issues either, so
* we just set them to 100.0 because those are nice values.
* The site accepts AADL processors.
*/
final SiteArchitecture siteArchitecture = new SiteArchitecture();
AADLProcessor ap = AADLProcessor.PROTOTYPE;
final Site theSite = new Site(100.0, 100.0, new SiteGuest[] { ap });
siteArchitecture.addSite(theSite);
/*
* The hardware is fixed based on the AADL specification, so we
* use the NoExpansionExpansor to keep the hardware from being
* generated for us.
*/
expansor.setSiteArchitecture(siteArchitecture);
/*
* Populate the problem space based on the AADL specification. First
* we walk the instance model and add all the processors. Then we
* walk the instance model again to add all the threads.
*/
OutDegreeAssignmentProblem problem1 = new OutDegreeAssignmentProblem(new OutDegreeComparator(), new BandwidthComparator(), new CapacityComparator());
problem1.setErrorReporter(new BinPackErrorReporter());
final OutDegreeAssignmentProblem problem = problem1;
// Add procs
final ForAllElement addProcessors = new ForAllElement(errManager) {
@Override
public void process(Element obj) {
ComponentInstance ci = (ComponentInstance) obj;
// the createInstance method already assigns a default MIPS if none exists
double mips = GetProperties.getProcessorMIPS(ci);
// checking consistency;
existsProcessorWithMIPS |= (mips != 0);
existsProcessorWithoutMIPS |= (mips == 0);
final AADLProcessor proc = AADLProcessor.createInstance(ci);
if (proc != null) {
System.out.println("Processor cycles Per sec:" + proc.getCyclesPerSecond());
siteArchitecture.addSiteGuest(proc, theSite);
problem.getHardwareGraph().add(proc);
// add reverse mapping
procToHardware.put(ci, proc);
}
}
};
addProcessors.processPreOrderComponentInstance(root, ComponentCategory.PROCESSOR);
/*
* Get all the links
*/
final ForAllElement addBuses = new ForAllElement(errManager) {
@Override
public void process(Element obj) {
ComponentInstance bi = (ComponentInstance) obj;
final AADLBus bus = AADLBus.createInstance(bi);
busToHardware.put(bi, bus);
}
};
addBuses.processPreOrderComponentInstance(root, ComponentCategory.BUS);
/*
* create the links between processors and busses
* (i.e., process connections)
*/
for (final Iterator<ConnectionInstance> i = root.getAllConnectionInstances().iterator(); i.hasNext(); ) {
final ConnectionInstance connInst = i.next();
if (connInst.getKind() == ConnectionKind.ACCESS_CONNECTION) {
InstanceObject src = connInst.getSource();
InstanceObject dst = connInst.getDestination();
AADLBus bus = null;
AADLProcessor processor = null;
// swap if i got them in the opposite order
if (src instanceof FeatureInstance) {
InstanceObject tmp = dst;
dst = src;
src = tmp;
}
bus = busToHardware.get(src);
FeatureInstance fi = (FeatureInstance) dst;
processor = procToHardware.get(fi.getContainingComponentInstance());
if (bus != null && processor != null) {
bus.add(processor);
processor.attachToLink(bus);
}
}
}
for (Iterator<AADLBus> iBus = busToHardware.values().iterator(); iBus.hasNext(); ) {
AADLBus bus = iBus.next();
problem.addLink(bus);
siteArchitecture.addSiteGuest(bus, theSite);
}
// Add threads
final ForAllElement addThreads = new ForAllElement(errManager) {
@Override
public void process(Element obj) {
final ComponentInstance ci = (ComponentInstance) obj;
/**
* JD - check the modes according to what was
* suggested by Dave.
*/
boolean selected = true;
if (som.getCurrentModes().size() > 0) {
selected = false;
for (ModeInstance mi : ci.getInModes()) {
if (mi == som.getCurrentModes().get(0)) {
selected = true;
}
}
}
if (!selected) {
return;
}
final AADLThread thread = AADLThread.createInstance(ci);
double refmips = GetProperties.getReferenceMIPS(ci);
// validate consistency
existsThreadWithReferenceProcessor |= (refmips != 0);
existsThreadWithoutReferenceProcessor |= (refmips == 0);
problem.getSoftwareGraph().add(thread);
// logInfo(thread.getReport());
// add reverse mapping
threadToSoftwareNode.put(ci, thread);
// Process NOT_COLLOCATED property.
RecordValue disjunctFrom = GetProperties.getNotCollocated(ci);
if (disjunctFrom == null) {
return;
}
final Set<ComponentInstance> disjunctSet = new HashSet<>();
ListValue tvl = (ListValue) PropertyUtils.getRecordFieldValue(disjunctFrom, "Targets");
for (PropertyExpression ref : tvl.getOwnedListElements()) {
/*
* Add all the instances rooted at the named instance.
* For example, the thread may be declared to be disjunct
* from another process, so we really want to be disjunct
* from the other threads contained in that process.
*/
final InstanceReferenceValue rv = (InstanceReferenceValue) ref;
final ComponentInstance refCI = (ComponentInstance) rv.getReferencedInstanceObject();
disjunctSet.addAll(refCI.getAllComponentInstances());
}
if (!disjunctSet.isEmpty()) {
notCollocated.put(ci, disjunctSet);
}
}
};
addThreads.processPreOrderComponentInstance(root, ComponentCategory.THREAD);
// only some processors have mips
if (existsProcessorWithMIPS && existsProcessorWithoutMIPS) {
errManager.error(root, "Not all processors have MIPSCapacity");
return null;
}
// only some threads with reference processor
if (existsThreadWithReferenceProcessor && existsThreadWithoutReferenceProcessor) {
errManager.error(root, "Not all threads have execution time reference processor");
return null;
}
// threads and processors mips spec not consistent
if (existsProcessorWithMIPS && existsThreadWithoutReferenceProcessor) {
errManager.error(root, "There are some processors with MIPSCapacity but some threads without execution time reference processors");
return null;
}
if (existsProcessorWithoutMIPS && existsThreadWithReferenceProcessor) {
errManager.error(root, "There are some threads with execution time reference processors but not all processors have MIPSCapacity");
return null;
}
// Add thread connections (Messages)
for (final Iterator<ConnectionInstance> i = root.getAllConnectionInstances().iterator(); i.hasNext(); ) {
final ConnectionInstance connInst = i.next();
if (connInst.getKind() == ConnectionKind.PORT_CONNECTION) {
if (!(connInst.getSource() instanceof FeatureInstance && connInst.getDestination() instanceof FeatureInstance)) {
continue;
}
final FeatureInstance src = (FeatureInstance) connInst.getSource();
final FeatureInstance dst = (FeatureInstance) connInst.getDestination();
final ComponentInstance ci = src.getContainingComponentInstance();
AADLThread t1 = threadToSoftwareNode.get(ci);
AADLThread t2 = threadToSoftwareNode.get(dst.getContainingComponentInstance());
if (t1 != null && t2 != null) {
Feature srcAP = src.getFeature();
// TODO: get the property directly
Classifier cl = srcAP.getClassifier();
if (cl instanceof DataClassifier) {
DataClassifier srcDC = (DataClassifier) cl;
double dataSize = 0.0;
double threadPeriod = 0.0;
try {
dataSize = AadlContribUtils.getDataSize(srcDC, SizeUnits.BYTES);
} catch (Exception e) {
errManager.warning(connInst, "No Data Size for connection");
}
try {
threadPeriod = GetProperties.getPeriodinNS(ci);
} catch (Exception e) {
errManager.warning(connInst, "No Period for connection");
}
// Now I can create the Message
Message msg = new Message((long) dataSize, (long) threadPeriod, (long) threadPeriod, t1, t2);
System.out.println(">>>>>>>>>> Adding message (" + Long.toString((long) dataSize) + "/" + Long.toString((long) threadPeriod) + ") between " + t1.getName() + " and " + t2.getName() + " based on connection " + connInst.getName());
problem.addMessage(msg);
} else {
errManager.warning(connInst, "No Data Classifier for connection");
}
}
}
}
// Add collocation constraints
for (final Iterator<ComponentInstance> constrained = notCollocated.keySet().iterator(); constrained.hasNext(); ) {
final ComponentInstance ci = constrained.next();
final SoftwareNode sn = threadToSoftwareNode.get(ci);
final Set<ComponentInstance> disjunctFrom = notCollocated.get(ci);
for (final Iterator<ComponentInstance> dfIter = disjunctFrom.iterator(); dfIter.hasNext(); ) {
/*
* Items in the disjunctFrom set do not have to be thread
* instances because of the way we add items to it (see above).
* We are only interested in the thread instances here, in
* particular because we only create SoftwareNodes for the
* thread instances, and we don't want to get null return
* values from the threadToSoftwareNode map.
*/
final ComponentInstance ci2 = dfIter.next();
if (ci2.getCategory() == ComponentCategory.THREAD) {
final SoftwareNode sn2 = threadToSoftwareNode.get(ci2);
final SoftwareNode[] disjunction = new SoftwareNode[] { sn, sn2 };
problem.addConstraint(new Disjoint(disjunction));
}
}
}
/*
* Add Allowed_Processor_Binding and
* Allowed_Processor_Binding_Class constraints
*/
for (final Iterator<ComponentInstance> i = threads.iterator(); i.hasNext(); ) {
final ComponentInstance thr = i.next();
final SoftwareNode thrSN = threadToSoftwareNode.get(thr);
Collection<ComponentInstance> allowed = getActualProcessorBindings(thr);
if (allowed.size() == 0) {
allowed = getAllowedProcessorBindings(thr);
}
if (allowed.size() > 0) {
final Object[] allowedProcs = new Object[allowed.size()];
int idx = 0;
for (Iterator<ComponentInstance> j = allowed.iterator(); j.hasNext(); idx++) {
final ComponentInstance proc = j.next();
allowedProcs[idx] = procToHardware.get(proc);
}
problem.addConstraint(new SetConstraint(new SoftwareNode[] { thrSN }, allowedProcs));
}
}
// Try to bin pack
final NFCHoBinPacker highPacker = new NFCHoBinPacker(packer);
final boolean res = highPacker.solve(problem);
return new AssignmentResult(problem, res);
}
use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.
the class AadlBaNameResolver method propertyFieldIndexResolver.
private boolean propertyFieldIndexResolver(Element el, IntegerValue field, BasicProperty bProperty, int fieldIndex, DeclarativePropertyName declProName) {
if (integerValueResolver(field)) {
// Link to the default value, if it exists.
if (Aadl2Package.LIST_VALUE == el.eClass().getClassifierID() && propertyFieldListValueResolver(field, (ListValue) el, fieldIndex, declProName)) {
return true;
} else if (Aadl2Package.PROPERTY_ASSOCIATION == el.eClass().getClassifierID()) {
PropertyAssociation pa = (PropertyAssociation) el;
ModalPropertyValue mpv = pa.getOwnedValues().get(pa.getOwnedValues().size() - 1);
PropertyExpression pe = mpv.getOwnedValue();
if (Aadl2Package.LIST_VALUE == pe.eClass().getClassifierID()) {
return propertyFieldListValueResolver(field, (ListValue) pe, fieldIndex, declProName);
}
}
// the else statements: link with the property type.
ListType lt = (ListType) bProperty.getPropertyType();
declProName.setOsateRef(lt.getElementType());
return true;
} else {
return false;
}
}
use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.
the class AadlBaNameResolver method structOrUnionOrArrayIdResolver.
// Resolves the given identifier within the property Data_Model::Element
// Names of a declared struct or union component (event if element names is
// set). If the given component is not declared as a struct or union, it
// returns false and reports error according to the hasToReport flag.
private boolean structOrUnionOrArrayIdResolver(Identifier id, DataClassifier component, boolean hasToReport) {
boolean result = false;
DataRepresentation rep = AadlBaUtils.getDataRepresentation(component);
if (rep == DataRepresentation.STRUCT || rep == DataRepresentation.UNION) {
EList<PropertyExpression> lpv = PropertyUtils.findPropertyExpression(component, DataModelProperties.ELEMENT_NAMES);
ListValue lv = null;
StringLiteral sl = null;
int index1 = 0;
int index2 = 0;
for1: for (PropertyExpression pe : lpv) {
lv = (ListValue) pe;
for (PropertyExpression pex : lv.getOwnedListElements()) {
sl = (StringLiteral) pex;
if (id.getId().equalsIgnoreCase(sl.getValue())) {
result = true;
break for1;
}
index2++;
}
index1++;
}
// Binds the element name's base type.
if (result) {
EList<PropertyExpression> lpv2 = PropertyUtils.findPropertyExpression(component, DataModelProperties.BASE_TYPE);
ClassifierValue cv;
cv = (ClassifierValue) ((ListValue) lpv2.get(index1)).getOwnedListElements().get(index2);
id.setOsateRef(cv);
}
} else if (rep == DataRepresentation.ARRAY) {
EList<PropertyExpression> lpv = PropertyUtils.findPropertyExpression(component, DataModelProperties.BASE_TYPE);
if (lpv.isEmpty() == false) {
ClassifierValue cv;
cv = (ClassifierValue) ((ListValue) lpv.get(0)).getOwnedListElements().get(0);
result = identifierComponentResolver(id, cv.getClassifier(), hasToReport);
} else {
result = false;
}
}
if (!result && hasToReport) {
reportNameError(id, id.getId());
}
return result;
}
use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.
the class AadlBaUtils method getBaseType.
/**
* Returns the last value of the base type property of the given component or
* {@code null} if the base type property is not set.
*
* @param component the given component
* @return the last value of the base type property or {@code null}
*/
public static ClassifierValue getBaseType(Classifier component) {
PropertyExpression pe;
EList<PropertyExpression> le;
Element el;
EList<PropertyExpression> lpe = PropertyUtils.findPropertyExpression(component, DataModelProperties.BASE_TYPE);
if (lpe != null && (!lpe.isEmpty())) {
pe = lpe.get(lpe.size() - 1);
// Syntax with ()
if (pe instanceof ListValue) {
le = ((ListValue) pe).getOwnedListElements();
if (le != null && (!le.isEmpty())) {
el = le.get(le.size() - 1);
if (el instanceof ClassifierValue) {
return (ClassifierValue) el;
}
}
} else // Syntax without ()
if (pe instanceof ClassifierValue) {
return (ClassifierValue) pe;
}
}
return null;
}
use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.
the class AadlBaUtils method processArrayDataRepresentation.
// Evaluates the array behavior of the given type in the Data Model Annex
// standard way. Set up dimension and dimension sizes of the given
// TypeHolder object.
// The given expression dimension is used as an dimension offset.
private static void processArrayDataRepresentation(Element el, TypeHolder type, int exprDim) throws DimensionException {
// Treats only type declared as an array. Otherwise returns.
if (type.getDataRep() == DataRepresentation.ARRAY) {
// Fetches the array element data type.
ClassifierValue cv = AadlBaUtils.getBaseType(type.getKlass());
if (cv != null && cv.getClassifier() instanceof DataClassifier) {
DataClassifier dc = (DataClassifier) cv.getClassifier();
type.setKlass(dc);
type.setDataRep(AadlBaUtils.getDataRepresentation(dc));
} else {
type.setKlass(null);
}
EList<PropertyExpression> pel = PropertyUtils.findPropertyExpression(type.getKlass(), DataModelProperties.DIMENSION);
int declareDimBT = 0;
long[] declareDimSizeBT;
if (false == pel.isEmpty()) {
// pel has only one element, according to AADL core standard.
PropertyExpression pe = pel.get(pel.size() - 1);
if (pe instanceof ListValue) {
ListValue lv = (ListValue) pe;
EList<PropertyExpression> lve = lv.getOwnedListElements();
declareDimBT = lve.size();
if (declareDimBT >= exprDim) {
declareDimSizeBT = new long[declareDimBT - exprDim];
for (int i = exprDim; i < declareDimBT; i++) {
IntegerLiteral il = (IntegerLiteral) lve.get(i);
declareDimSizeBT[i - exprDim] = il.getValue();
}
type.setDimension(declareDimBT - exprDim);
type.setDimensionSizes(declareDimSizeBT);
} else {
String msg = "must be an array but is resolved as " + type.getKlass().getQualifiedName();
throw new DimensionException(el, msg, false);
}
}
} else {
// Returning -1 and null means that the expression is declared as an
// array but the dimension property is not set.
type.setDimension(-1);
type.setDimensionSizes(null);
return;
// String msg = "is declared as an array but the dimension property is not set" ;
// throw new DimensionException(el, msg, true) ;
}
} else {
return;
}
}
Aggregations