lib/AdaptationEngine.js
function (diffSeq, targetModel) {
		var self = this;
		this.targetModel = targetModel;

		// know if a trace has already been added to cmdList for {path <-> AdaptationPrimitive}
		var traceAlreadyProcessed = function (cmd) {
			return self.alreadyProcessedTraces[cmd.modelElement.path()] && self.alreadyProcessedTraces[cmd.modelElement.path()][cmd.toString()];
		};

		// add a trace to the processed trace map
		var addProcessedTrace = function (cmd) {
			self.alreadyProcessedTraces[cmd.modelElement.path()] = self.alreadyProcessedTraces[cmd.modelElement.path()] || {};
			self.alreadyProcessedTraces[cmd.modelElement.path()][cmd.toString()] = cmd;
		};

		// fill adaptation primitives list
		var cmdList = [];
		diffSeq.traces.array.forEach(function (trace) {
			self.processTrace(trace).forEach(function (cmd) {
				if (!traceAlreadyProcessed(cmd)) {
					cmdList.push(cmd);
					addProcessedTrace(cmd);
				}
			});
		});

		// clean primitives:
		//  - don't call UpdateInstance when (Start|Stop)Instance will be executed
		for (var path in this.alreadyProcessedTraces) {
			if (this.alreadyProcessedTraces[path][UpdateInstance.prototype.toString()]) {
				for (var type in this.alreadyProcessedTraces[path]) {
					if (type === StopInstance.prototype.toString() || type === StartInstance.prototype.toString()) {
						var index = cmdList.indexOf(this.alreadyProcessedTraces[path][UpdateInstance.prototype.toString()]);
						if (index > -1) {
							cmdList.splice(index, 1);
						}
					}
				}
			}
		}

		// free-up some mem
		this.targetModel = null;
		this.alreadyProcessedTraces = {};

		//return sorted command list (sort by COMMAND_RANK in order to process adaptations properly)
		// this.sortCommands(cmdList).forEach(function (cmd) {
		//   var tag = cmd.toString();
		//   while (tag.length < 20) {
		//     tag += ' ';
		//   }
		//   console.log(tag, cmd.modelElement.path());
		// });
		return this.sortCommands(cmdList);
	}
function (diffSeq, targetModel) {
		var self = this;
		this.targetModel = targetModel;

		// know if a trace has already been added to cmdList for {path <-> AdaptationPrimitive}
		var traceAlreadyProcessed = function (cmd) {
			return self.alreadyProcessedTraces[cmd.modelElement.path()] && self.alreadyProcessedTraces[cmd.modelElement.path()][cmd.toString()];
		};

		// add a trace to the processed trace map
		var addProcessedTrace = function (cmd) {
			self.alreadyProcessedTraces[cmd.modelElement.path()] = self.alreadyProcessedTraces[cmd.modelElement.path()] || {};
			self.alreadyProcessedTraces[cmd.modelElement.path()][cmd.toString()] = cmd;
		};

		// fill adaptation primitives list
		var cmdList = [];
		diffSeq.traces.array.forEach(function (trace) {
			self.processTrace(trace).forEach(function (cmd) {
				if (!traceAlreadyProcessed(cmd)) {
					cmdList.push(cmd);
					addProcessedTrace(cmd);
				}
			});
		});

		// clean primitives:
		//  - don't call UpdateInstance when (Start|Stop)Instance will be executed
		for (var path in this.alreadyProcessedTraces) {
			if (this.alreadyProcessedTraces[path][UpdateInstance.prototype.toString()]) {
				for (var type in this.alreadyProcessedTraces[path]) {
					if (type === StopInstance.prototype.toString() || type === StartInstance.prototype.toString()) {
						var index = cmdList.indexOf(this.alreadyProcessedTraces[path][UpdateInstance.prototype.toString()]);
						if (index > -1) {
							cmdList.splice(index, 1);
						}
					}
				}
			}
		}

		// free-up some mem
		this.targetModel = null;
		this.alreadyProcessedTraces = {};

		//return sorted command list (sort by COMMAND_RANK in order to process adaptations properly)
		// this.sortCommands(cmdList).forEach(function (cmd) {
		//   var tag = cmd.toString();
		//   while (tag.length < 20) {
		//     tag += ' ';
		//   }
		//   console.log(tag, cmd.modelElement.path());
		// });
		return this.sortCommands(cmdList);
	}
function ( diffSeq , targetModel ) { var self = this ; this . targetModel = targetModel ; // know if a trace has already been added to cmdList for {path <-> AdaptationPrimitive} var traceAlreadyProcessed = function ( cmd ) { return self . alreadyProcessedTraces [ cmd . modelElement . path ( ) ] && self . alreadyProcessedTraces [ cmd . modelElement . path ( ) ] [ cmd . toString ( ) ] ; } ; // add a trace to the processed trace map var addProcessedTrace = function ( cmd ) { self . alreadyProcessedTraces [ cmd . modelElement . path ( ) ] = self . alreadyProcessedTraces [ cmd . modelElement . path ( ) ] || { } ; self . alreadyProcessedTraces [ cmd . modelElement . path ( ) ] [ cmd . toString ( ) ] = cmd ; } ; // fill adaptation primitives list var cmdList = [ ] ; diffSeq . traces . array . forEach ( function ( trace ) { self . processTrace ( trace ) . forEach ( function ( cmd ) { if ( ! traceAlreadyProcessed ( cmd ) ) { cmdList . push ( cmd ) ; addProcessedTrace ( cmd ) ; } } ) ; } ) ; // clean primitives: //  - don't call UpdateInstance when (Start|Stop)Instance will be executed for ( var path in this . alreadyProcessedTraces ) { if ( this . alreadyProcessedTraces [ path ] [ UpdateInstance . prototype . toString ( ) ] ) { for ( var type in this . alreadyProcessedTraces [ path ] ) { if ( type === StopInstance . prototype . toString ( ) || type === StartInstance . prototype . toString ( ) ) { var index = cmdList . indexOf ( this . alreadyProcessedTraces [ path ] [ UpdateInstance . prototype . toString ( ) ] ) ; if ( index > - 1 ) { cmdList . splice ( index , 1 ) ; } } } } } // free-up some mem this . targetModel = null ; this . alreadyProcessedTraces = { } ; //return sorted command list (sort by COMMAND_RANK in order to process adaptations properly) // this.sortCommands(cmdList).forEach(function (cmd) { //   var tag = cmd.toString(); //   while (tag.length < 20) { //     tag += ' '; //   } //   console.log(tag, cmd.modelElement.path()); // }); return this . sortCommands ( cmdList ) ; }
Process traces to find the right adaptation primitive command
Returns a command to execute in order to do the adaptation logic
@param diffSeq
@param targetModel
@returns {Array}
Process traces to find the right adaptation primitive command Returns a command to execute in order to do the adaptation logic