leaf-analysis/src/simulation/BIModelSpecBuilder.java
/** Main function that generates the model spec.
	 * @param inObject
	 * @return A complete model of type ModelSpec
	 */
Main function that generates the model spec.
@param inObject
@return A complete model of type ModelSpec
Main function that generates the model spec . @param inObject @return A complete model of type ModelSpec
public static ModelSpec buildModelSpec(IMain inObject){
		try {
			ModelSpec modelSpec = new ModelSpec();	
			IGraph frontendModel = inObject.getGraph();
			List<ICell> allCells = frontendModel.getCells();
			List<ICell> actors = new ArrayList<ICell>();
			List<ICell> intentions = new ArrayList<ICell>();
			List<ICell> links = new ArrayList<ICell>();
			if (!allCells.isEmpty()) {
				for(ICell cell: allCells){
					if (cell.getType().equals("basic.Actor") && cell.getActor() != null) 
						actors.add(cell);
					else if (cell.getIntention() != null && (cell.getType().equals("basic.Task") ||
							cell.getType().equals("basic.Goal") || cell.getType().equals("basic.Softgoal") ||
							cell.getType().equals("basic.Resource")))
						intentions.add(cell);
					else if (cell.getLink() != null && 
							((cell.getType().equals("element")) ||(cell.getType().equals("basic.CellLink"))))
						links.add(cell);
					else
						throw new IllegalArgumentException("Cell with unknown type: " + cell.getType());	
				}
			}
			readAnalysisParameters(modelSpec, inObject.getAnalysisRequest(),
					intentions.size()); 
			readOverallGraphParameters(modelSpec, frontendModel);	
			if (!actors.isEmpty()) {
				int actorID = 0;
				for(ICell dataActor: actors){
					String backID = "A" + String.format("%03d", actorID);
					actorID ++;
					modelSpec.getActors().add(new Actor(backID,	dataActor.getActor().getActorName(), 
							dataActor.getActor().getType(),	dataActor.getId()));
				}
			}
			if (Main.DEBUG) System.out.println("Read Actors");
			if(!intentions.isEmpty()){			
				for (ICell dataIntention : intentions){
					Intention newInt = Intention.createIntention(dataIntention, modelSpec);
					modelSpec.getIntentions().add(newInt); 
				}
			}
			if (Main.DEBUG) System.out.println("Read Elements");
			if(!links.isEmpty()) {
				ArrayList<ICell> allDecompositionLinks = new ArrayList<ICell>();
				List<NotBothLink> notBothLink = new ArrayList<NotBothLink>();
				/* Start to new contribution code. To replace both contribution and evolving contribution. */
				List<ContributionLink> contributionLinks = new ArrayList<ContributionLink>();
				for (ICell link : links){
					String linkType = link.getLink().getLinkType();
					String linkSrcID = link.getSourceID();
					String linkDestID = link.getTargetID();
					Intention intentElementSrc = modelSpec.getIntentionByUniqueID(linkSrcID);
					Intention intentElementDest = modelSpec.getIntentionByUniqueID(linkDestID);
					if (linkType.equals("NBT"))
						notBothLink.add(new NotBothLink(intentElementSrc, intentElementDest, false, 
								link.getLink().getAbsTime(), link.getId()));
					else if (linkType.equals("NBD"))	
						notBothLink.add(new NotBothLink(intentElementSrc, intentElementDest, true, 
								link.getLink().getAbsTime(), link.getId()));
					else {
						ContributionLink tempCont = ContributionLink.createConstributionLink(intentElementSrc, 
								intentElementDest, link.getLink(), link.getId());
						if (tempCont != null)
							contributionLinks.add(tempCont);
						else
							allDecompositionLinks.add(link);
					}
				}
				modelSpec.setNotBothLink(notBothLink);
				modelSpec.setContributionLinks(contributionLinks); 
				modelSpec.setDecompositionLinks(DecompositionLink.createDecompositionLinks(allDecompositionLinks, 
						modelSpec));
			}
			if (frontendModel.getConstraints() != null)
				modelSpec.applyConstraints(frontendModel.getConstraints());
			if (Main.DEBUG) System.out.println("Added model constraints.");
			if (Main.DEBUG) System.out.println("Returning Model Spec!!!!");
			return modelSpec;
		} catch (Exception e) {
			throw new RuntimeException(e.getMessage());
		}
	}
public static ModelSpec buildModelSpec ( IMain inObject ) { try { ModelSpec modelSpec = new ModelSpec ( ) ; IGraph frontendModel = inObject . getGraph ( ) ; List < ICell > allCells = frontendModel . getCells ( ) ; List < ICell > actors = new ArrayList < ICell > ( ) ; List < ICell > intentions = new ArrayList < ICell > ( ) ; List < ICell > links = new ArrayList < ICell > ( ) ; if ( ! allCells . isEmpty ( ) ) { for ( ICell cell : allCells ) { if ( cell . getType ( ) . equals ( "basic.Actor" ) && cell . getActor ( ) != null ) actors . add ( cell ) ; else if ( cell . getIntention ( ) != null && ( cell . getType ( ) . equals ( "basic.Task" ) || cell . getType ( ) . equals ( "basic.Goal" ) || cell . getType ( ) . equals ( "basic.Softgoal" ) || cell . getType ( ) . equals ( "basic.Resource" ) ) ) intentions . add ( cell ) ; else if ( cell . getLink ( ) != null && ( ( cell . getType ( ) . equals ( "element" ) ) || ( cell . getType ( ) . equals ( "basic.CellLink" ) ) ) ) links . add ( cell ) ; else throw new IllegalArgumentException ( "Cell with unknown type: " + cell . getType ( ) ) ; } } readAnalysisParameters ( modelSpec , inObject . getAnalysisRequest ( ) , intentions . size ( ) ) ; readOverallGraphParameters ( modelSpec , frontendModel ) ; if ( ! actors . isEmpty ( ) ) { int actorID = 0 ; for ( ICell dataActor : actors ) { String backID = "A" + String . format ( "%03d" , actorID ) ; actorID ++ ; modelSpec . getActors ( ) . add ( new Actor ( backID , dataActor . getActor ( ) . getActorName ( ) , dataActor . getActor ( ) . getType ( ) , dataActor . getId ( ) ) ) ; } } if ( Main . DEBUG ) System . out . println ( "Read Actors" ) ; if ( ! intentions . isEmpty ( ) ) { for ( ICell dataIntention : intentions ) { Intention newInt = Intention . createIntention ( dataIntention , modelSpec ) ; modelSpec . getIntentions ( ) . add ( newInt ) ; } } if ( Main . DEBUG ) System . out . println ( "Read Elements" ) ; if ( ! links . isEmpty ( ) ) { ArrayList < ICell > allDecompositionLinks = new ArrayList < ICell > ( ) ; List < NotBothLink > notBothLink = new ArrayList < NotBothLink > ( ) ; /* Start to new contribution code. To replace both contribution and evolving contribution. */ List < ContributionLink > contributionLinks = new ArrayList < ContributionLink > ( ) ; for ( ICell link : links ) { String linkType = link . getLink ( ) . getLinkType ( ) ; String linkSrcID = link . getSourceID ( ) ; String linkDestID = link . getTargetID ( ) ; Intention intentElementSrc = modelSpec . getIntentionByUniqueID ( linkSrcID ) ; Intention intentElementDest = modelSpec . getIntentionByUniqueID ( linkDestID ) ; if ( linkType . equals ( "NBT" ) ) notBothLink . add ( new NotBothLink ( intentElementSrc , intentElementDest , false , link . getLink ( ) . getAbsTime ( ) , link . getId ( ) ) ) ; else if ( linkType . equals ( "NBD" ) ) notBothLink . add ( new NotBothLink ( intentElementSrc , intentElementDest , true , link . getLink ( ) . getAbsTime ( ) , link . getId ( ) ) ) ; else { ContributionLink tempCont = ContributionLink . createConstributionLink ( intentElementSrc , intentElementDest , link . getLink ( ) , link . getId ( ) ) ; if ( tempCont != null ) contributionLinks . add ( tempCont ) ; else allDecompositionLinks . add ( link ) ; } } modelSpec . setNotBothLink ( notBothLink ) ; modelSpec . setContributionLinks ( contributionLinks ) ; modelSpec . setDecompositionLinks ( DecompositionLink . createDecompositionLinks ( allDecompositionLinks , modelSpec ) ) ; } if ( frontendModel . getConstraints ( ) != null ) modelSpec . applyConstraints ( frontendModel . getConstraints ( ) ) ; if ( Main . DEBUG ) System . out . println ( "Added model constraints." ) ; if ( Main . DEBUG ) System . out . println ( "Returning Model Spec!!!!" ) ; return modelSpec ; } catch ( Exception e ) { throw new RuntimeException ( e . getMessage ( ) ) ; } }
Main function that generates the model spec.
Main function that generates the model spec .
// Back-end Model // Collection of Cells // Divide cells into actors, intentions, and links. // Read the parameters associated with the model. // **** ACTORS **** - Getting Actor Data // **** INTENTIONS **** - Getting intentional elements //Getting links // Temporary Place Holder to Collect Decomposition Links. // List to hold newly created links. // After all intentions, relationship, and function have been establish, then apply constraints.