示例#1
0
            public int Compare(object x, object y)
            {
                IExchangeItem itemX = (IExchangeItem)x;
                IExchangeItem itemY = (IExchangeItem)y;

                int result = string.Compare(itemX.Quantity.ID, itemY.Quantity.ID, false);

                if (result == 0)
                {
                    result = string.Compare(itemX.ElementSet.ID, itemY.ElementSet.ID, false);
                }

                return(result);
            }
示例#2
0
        public void OscillatorModelTest()
        {
            IModelFactory oscillatorModelFactory = new SimpleOscillatorModelFactory();

            oscillatorModelFactory.Initialize(".", new[] { "../../testData/OpenDaOscillBB/OscillatorModel.xml" });

            string[]       modelInstanceArguments = new[] { "this argument is not used" };
            IModelInstance modelInstance          = oscillatorModelFactory.GetInstance(modelInstanceArguments,
                                                                                       (int)OutputLevel.ModelDefault);

            IList <string> exchangeItemIDs = modelInstance.ExchangeItemIDs;

            Assert.IsTrue(exchangeItemIDs.Count > 0, "At least one EI");
            IExchangeItem thirdExchangeItem = modelInstance.GetExchangeItem(exchangeItemIDs[2]);

            Assert.AreEqual(AbstractModelInstance.StartTimeId, thirdExchangeItem.Id, "3th exchange item is t_start");

            double startTime = modelInstance.TimeHorizon.BeginTime.MJD;
            double endTime   = modelInstance.TimeHorizon.EndTime.MJD;
            double inBetween = startTime + (startTime + endTime) * 3 / 8;

            modelInstance.Compute(new Time(inBetween));

            IExchangeItem stateExchangeItem0 = modelInstance.GetExchangeItem(SimpleOscillatorModelInstance.State0Id);
            IExchangeItem stateExchangeItem1 = modelInstance.GetExchangeItem(SimpleOscillatorModelInstance.State1Id);

            // check state values
            double[] stateInBetween0 = stateExchangeItem0.ValuesAsDoubles;
            double[] stateInBetween1 = stateExchangeItem1.ValuesAsDoubles;

            Assert.AreEqual(1, stateInBetween0.Length, "#values in state");
            Assert.AreEqual(1, stateInBetween1.Length, "#values in state");
            Assert.AreEqual(-0.0189262285d, stateInBetween0[0], 1e-10, "stateInBetween[0]");
            Assert.AreEqual(0.19278554285d, stateInBetween1[0], 1e-10, "stateInBetween[1]");

            modelInstance.Compute(new Time(endTime));

            // check state values
            double[] stateValuesAtEnd0 = stateExchangeItem0.ValuesAsDoubles;
            double[] stateValuesAtEnd1 = stateExchangeItem1.ValuesAsDoubles;
            Assert.AreEqual(0.00509791929d, stateValuesAtEnd0[0], 1e-10, "stateValuesAtEnd[0]");
            Assert.AreEqual(0.00234214853d, stateValuesAtEnd1[0], 1e-10, "stateValuesAtEnd[1]");

            // assert that previous state values were a copy and are therefore unchanged
            Assert.AreEqual(-0.0189262285d, stateInBetween0[0], 1e-10, "stateValues[0]");
            Assert.AreEqual(0.19278554285d, stateInBetween1[0], 1e-10, "stateValues[1]");

            modelInstance.Finish();
        }
示例#3
0
 public override bool IsAvailable(IExchangeItem querySpecifier)
 {
     CheckBuffer();
     if (buffer.TimesCount > 0)
     {
         ITime         lastTimeInBuffer      = buffer.GetTimeAt(buffer.TimesCount - 1);
         IList <ITime> consumerTimes         = querySpecifier.TimeSet.Times;
         ITime         lastConsumerTime      = consumerTimes[consumerTimes.Count - 1];
         const double  epsilon               = 1e-10;
         double        lastConsumerTimeAsMJD = lastConsumerTime.StampAsModifiedJulianDay +
                                               lastConsumerTime.DurationInDays;
         double lastTimeInBufferAsMJD = lastTimeInBuffer.StampAsModifiedJulianDay +
                                        lastTimeInBuffer.DurationInDays;
         return(lastConsumerTimeAsMJD < (lastTimeInBufferAsMJD + epsilon));
     }
     return(false);
 }
示例#4
0
        public void OscillatorBBStochModelTest()
        {
            // force loading assembly
            SimpleOscillatorModelFactory dummyFactory = null;

            IStochModelFactory bbStochModelFactory = new BBStochModelFactoryJ2N();

            bbStochModelFactory.Initialize(".", new[] { "../../testData/OpenDaOscillBB/OscillatorStochBBModel.xml" });

            IStochModelInstance stochModelInstance = bbStochModelFactory.GetInstance((int)OutputLevel.ModelDefault);

            stochModelInstance.SetAutomaticNoiseGeneration(true);

            IList <string> exchangeItemIDs = stochModelInstance.ExchangeItemIDs;

            Assert.IsTrue(exchangeItemIDs.Count > 0, "At least one EI");
            IExchangeItem thirdExchangeItem = stochModelInstance.GetExchangeItem(exchangeItemIDs[2]);

            Assert.AreEqual(AbstractModelInstance.StartTimeId, thirdExchangeItem.Id, "3th exchange item is t_start");

            const double deltaT = 2.0d;

            for (int i = 0; i < 20; i++)
            {
                double targetTime = stochModelInstance.TimeHorizon.BeginTime.MJD + (i + 1) * deltaT;
                stochModelInstance.Compute(new Time(targetTime));
            }
            ;

            IExchangeItem stateExchangeItem0 = stochModelInstance.GetExchangeItem(SimpleOscillatorModelInstance.State0Id);
            IExchangeItem stateExchangeItem1 = stochModelInstance.GetExchangeItem(SimpleOscillatorModelInstance.State1Id);

            // check state values
            double[] stateValuesAtEnd0 = stateExchangeItem0.ValuesAsDoubles;
            double[] stateValuesAtEnd1 = stateExchangeItem1.ValuesAsDoubles;
            Assert.AreEqual(8.20208450421d, stateValuesAtEnd0[0], 1e-10, "stateValuesAtEnd[0]");
            Assert.AreEqual(-24.81797019751d, stateValuesAtEnd1[0], 1e-10, "stateValuesAtEnd[1]");

            stochModelInstance.Finish();
        }
示例#5
0
        /// <summary>
        /// Populates this <see cref="ConnectionDialog">ConnectionDialog</see> with specific connection.
        /// </summary>
        /// <param name="uilink"></param>
        /// <param name="startingLinkID"></param>
        public void PopulateDialog(UIConnection uilink, int startingLinkID)
        {
            _uilink               = uilink;
            _startingLinkID       = startingLinkID;
            _propertyManagerCache = new Hashtable();

            _shouldBeSaved = false;

            ElementTypeFilterCheckBox.Checked = false;
            DimensionFilterCheckBox.Checked   = false;

            int count;
            ILinkableComponent component;

            component = uilink.ProvidingModel.LinkableComponent;
            IExchangeItem[] outputExchangeItems = new IExchangeItem[component.OutputExchangeItemCount];
            count = component.OutputExchangeItemCount;
            for (int i = 0; i < count; i++)
            {
                outputExchangeItems[i] = component.GetOutputExchangeItem(i);
            }

            providerExchangeItemSelector.PopulateExchangeItemTree(outputExchangeItems, true);

            component = uilink.AcceptingModel.LinkableComponent;
            IExchangeItem[] inputExchangeItems = new IExchangeItem[component.InputExchangeItemCount];
            count = component.InputExchangeItemCount;
            for (int i = 0; i < count; i++)
            {
                inputExchangeItems[i] = component.GetInputExchangeItem(i);
            }

            acceptorExchangeItemSelector.PopulateExchangeItemTree(inputExchangeItems, true);

            UpdateListLinks();

            labelInfo.Text = "Connection " + uilink.ProvidingModel.ModelID + " => " + uilink.AcceptingModel.ModelID;
        }
示例#6
0
        private bool CheckIfDataOperationsAreValid()
        {
            bool isValid = true;

            IQuantity   providerQuantity, acceptorQuantity;
            IElementSet providerElementSet, acceptorElementSet;

            IDataOperation[] providerDataOperations, acceptorDataOperations;

            providerExchangeItemSelector.GetCheckedExchangeItem(out providerQuantity, out providerElementSet, out providerDataOperations);
            acceptorExchangeItemSelector.GetCheckedExchangeItem(out acceptorQuantity, out acceptorElementSet, out acceptorDataOperations);

            // Check if combination of providerDataOperations is valid
            if (providerDataOperations != null && providerElementSet != null && acceptorElementSet != null)
            {
                Debug.Assert(providerQuantity != null && acceptorQuantity != null);

                IExchangeItem outputExchangeItem = providerExchangeItemSelector.GetExchangeItem(providerQuantity, providerElementSet);
                IExchangeItem inputExchangeItem  = acceptorExchangeItemSelector.GetExchangeItem(acceptorQuantity, acceptorElementSet);

                Debug.Assert(outputExchangeItem != null && inputExchangeItem != null);
                Debug.Assert(outputExchangeItem is IOutputExchangeItem);
                Debug.Assert(inputExchangeItem is IInputExchangeItem);

                foreach (IDataOperation dataOperation in providerDataOperations)
                {
                    isValid = dataOperation.IsValid((IInputExchangeItem)inputExchangeItem, (IOutputExchangeItem)outputExchangeItem, providerDataOperations);
                    if (!isValid)
                    {
                        break;
                    }
                }
            }

            labelWarning.Visible = !isValid;
            return(isValid);
        }
        private String GetValueArrayName(IExchangeItem item)
        {
            // figure out the prefix
            var prefix = "";
            if (item is InputExchangeItem)
                prefix = "In";
            if (item is OutputExchangeItem)
                prefix = "Out";

            return prefix + "Values" + item.Quantity.ID.Replace(" ", "").ToUpper();
        }
        private void GenerateArrayAccessorsByElement(StreamWriter writer, String functionName, IExchangeItem[] items, String op)
        {
            if (op == "Get")
                writer.WriteLine(@"function[value] = " + functionName + "(quantityName, elementID)");
            else
                writer.WriteLine(@"function[] = " + functionName + "(quantityName, elementID, value)");

            foreach (var item in items)
            {
                writer.WriteLine(@"  global " + GetIDArrayName(item) + ";");
                writer.WriteLine(@"  global " + GetValueArrayName(item) + ";");
            }

            if (op == "Get")
                writer.WriteLine(@"  value = -999;");

            // step through each item in the list
            foreach (var item in items)
            {
                writer.WriteLine(@"  if(strcmp(quantityName, '" + item.Quantity.ID + "') == 1)");

                writer.WriteLine(@"    ids = " + GetIDArrayName(item) + ";");

                writer.WriteLine(@"    for i=1:size(ids, 1)");
                writer.WriteLine(@"      if(strcmp(elementID, strtrim(char(ids(i,:)))) == 1)");

                if (op == "Get")
                    writer.WriteLine(@"        value = " + GetValueArrayName(item) + "(i);");
                else
                    writer.WriteLine(@"        " + GetValueArrayName(item) + "(i) = value;");

                writer.WriteLine(@"        break;");
                writer.WriteLine(@"      end");
                writer.WriteLine(@"    end");

                writer.WriteLine(@"  end");
            }

            writer.WriteLine(@"return");
        }
		/// <summary>
		/// Populates this <see cref="ConnectionDialog">ConnectionDialog</see> with specific connection.
		/// </summary>
		/// <param name="uilink"></param>
		/// <param name="startingLinkID"></param>
		public void PopulateDialog( UIConnection uilink, int startingLinkID )
		{
			_uilink = uilink;
			_startingLinkID = startingLinkID;
			_propertyManagerCache = new Hashtable();

			_shouldBeSaved = false;

			ElementTypeFilterCheckBox.Checked = false;
			DimensionFilterCheckBox.Checked = false;

			int count;
			ILinkableComponent component;

			component = uilink.ProvidingModel.LinkableComponent;
			IExchangeItem[] outputExchangeItems = new IExchangeItem[ component.OutputExchangeItemCount ];
			count = component.OutputExchangeItemCount;			
			for( int i = 0; i < count; i++ )
				outputExchangeItems[i] = component.GetOutputExchangeItem(i);

			providerExchangeItemSelector.PopulateExchangeItemTree( outputExchangeItems, true );

			component = uilink.AcceptingModel.LinkableComponent;
			IExchangeItem[] inputExchangeItems = new IExchangeItem[ component.InputExchangeItemCount ];
			count = component.InputExchangeItemCount;
			for( int i = 0; i < count; i++ )
				inputExchangeItems[i] = component.GetInputExchangeItem(i);

			acceptorExchangeItemSelector.PopulateExchangeItemTree( inputExchangeItems, true );
			
			UpdateListLinks();
			
			labelInfo.Text = "Connection "+uilink.ProvidingModel.ModelID+" => "+uilink.AcceptingModel.ModelID;
		}
 public override IList GetValues(IExchangeItem querySpecifier)
 {
     return(Values);
 }
		/// <summary>
		/// Populates this control with exchange items.
		/// </summary>
		/// <param name="exchangeItems">Exchange items.</param>
		/// <param name="showCheckboxes">Determines whether to show check-boxes in the tree.</param>
		public void PopulateExchangeItemTree( IExchangeItem[] exchangeItems, bool showCheckboxes )
		{
			_checkedQuantity = null;
			_checkedElementSet = null;
			_checkedDataOperations = new ArrayList();

			_filterDimension = null;
			_filterElementSet = null;

			_blockAfterCheckEventHandler = false;

			_exchangeItems = new ArrayList( exchangeItems );

			ExchangeItemsComparer comparer = new ExchangeItemsComparer();
			_exchangeItems.Sort( comparer );
			

			// fill _exchangeItemsSearcher
			_exchangeItemsSearcher = new Hashtable();
			foreach( IExchangeItem exchangeItem in _exchangeItems )
			{
				if( exchangeItem.ElementSet==null || exchangeItem.Quantity==null )
					throw( new Exception("Exchange item cannot have ElementSet or Quantity null.") );

				string key = CreateExchangeItemID(exchangeItem.Quantity, exchangeItem.ElementSet);
				object entry = _exchangeItemsSearcher[ key ];
				
				if( entry == null )
				{
					// first usage of this key
					_exchangeItemsSearcher[key] = exchangeItem;
				}
				else if( entry is IExchangeItem )
				{
					// this key already used once => create ArrayList of exchange items with this key
					ArrayList list = new ArrayList();
					list.Add( entry );
					list.Add( exchangeItem );

					_exchangeItemsSearcher[key] = list;
				} 
				else
				{
					// key used more times
					((ArrayList)entry).Add( exchangeItem );
				}				
			}				

			treeView1.CheckBoxes = showCheckboxes;

			CreateTree();
		}
示例#12
0
 static ExchangeItem()
 {
     LogicServer.Instance.UpdateManager.InitStaticImpl(typeof(ExchangeItem), typeof(ExchangeItemDefaultImpl),
                                                       o => { mImpl = (IExchangeItem)o; });
 }
示例#13
0
		/// <summary>
		/// Selects one model to be shown in dialog.
		/// </summary>
		/// <param name="modelID">ID of model to be selected.</param>		
		public void SelectModel( string modelID )
		{
			if( modelID == null )
			{
				outputExchangeItemSelector.PopulateExchangeItemTree( new OutputExchangeItem[0], false );
				inputExchangeItemSelector.PopulateExchangeItemTree( new InputExchangeItem[0], false );
				_loadedModelID = null;
			}
			else
			{
				// find model by ID
				int modelIndex = -1;
				for( int i=0; i<comboBoxModel.Items.Count; i++ )
					if( (string)comboBoxModel.Items[i] == modelID )
					{
						modelIndex = i;
						break;
					}				
							
				if( modelIndex < 0 || modelIndex>=_uiModels.Count )
				{
					// model with modelID wasn't found 
					Debug.Assert( false );
					SelectModel( null );
					return;
				}

				UIModel selectedModel = (UIModel)_uiModels[ modelIndex ];

				Debug.Assert( selectedModel.ModelID == modelID );

				// load exchange items (if they aren't already loaded)
				if( modelID != _loadedModelID )
				{
					IExchangeItem[] outputExchangeItems = new IExchangeItem[ selectedModel.LinkableComponent.OutputExchangeItemCount ];
					for (int i = 0; i < selectedModel.LinkableComponent.OutputExchangeItemCount; i++)
						outputExchangeItems[i] = selectedModel.LinkableComponent.GetOutputExchangeItem( i );
					outputExchangeItemSelector.PopulateExchangeItemTree( outputExchangeItems, false );

					IExchangeItem[] inputExchangeItems = new IExchangeItem[ selectedModel.LinkableComponent.InputExchangeItemCount ];
					for (int i = 0; i < selectedModel.LinkableComponent.InputExchangeItemCount; i++)
						inputExchangeItems[i] = selectedModel.LinkableComponent.GetInputExchangeItem(i);
					inputExchangeItemSelector.PopulateExchangeItemTree( inputExchangeItems, false );

					_loadedModelID = selectedModel.ModelID;
				}

				// select model also in comboBox
				// this can cause this method is reentered
				comboBoxModel.SelectedIndex = modelIndex;

				//labelInfo.Text = "Model " + selectedModel.ModelID;

				// show properties of this model
				PropertyGridSelectObject( selectedModel.LinkableComponent );
			}
		}
        private void InitializeValuesArray(IExchangeItem item)
        {
            // build the 1d array to hold the id's
            Array values = new double[item.ElementSet.ElementCount];
            Array valuesi = new double[item.ElementSet.ElementCount];
            for (var i = 0; i < item.ElementSet.ElementCount; i++)
            {
                values.SetValue(-999, i);
            }

            // set the arrays
            matlab.PutFullMatrix(GetValueArrayName(item), "base", values, valuesi);
            matlab.Execute(GetValueArrayName(item) + " = " + GetValueArrayName(item) + "'");
        }
示例#15
0
        /// <summary>
        /// Selects one model to be shown in dialog.
        /// </summary>
        /// <param name="modelID">ID of model to be selected.</param>
        public void SelectModel(string modelID)
        {
            if (modelID == null)
            {
                outputExchangeItemSelector.PopulateExchangeItemTree(new OutputExchangeItem[0], false);
                inputExchangeItemSelector.PopulateExchangeItemTree(new InputExchangeItem[0], false);
                _loadedModelID = null;
            }
            else
            {
                // find model by ID
                int modelIndex = -1;
                for (int i = 0; i < comboBoxModel.Items.Count; i++)
                {
                    if ((string)comboBoxModel.Items[i] == modelID)
                    {
                        modelIndex = i;
                        break;
                    }
                }

                if (modelIndex < 0 || modelIndex >= _uiModels.Count)
                {
                    // model with modelID wasn't found
                    Debug.Assert(false);
                    SelectModel(null);
                    return;
                }

                UIModel selectedModel = (UIModel)_uiModels[modelIndex];

                Debug.Assert(selectedModel.ModelID == modelID);

                // load exchange items (if they aren't already loaded)
                if (modelID != _loadedModelID)
                {
                    IExchangeItem[] outputExchangeItems = new IExchangeItem[selectedModel.LinkableComponent.OutputExchangeItemCount];
                    for (int i = 0; i < selectedModel.LinkableComponent.OutputExchangeItemCount; i++)
                    {
                        outputExchangeItems[i] = selectedModel.LinkableComponent.GetOutputExchangeItem(i);
                    }
                    outputExchangeItemSelector.PopulateExchangeItemTree(outputExchangeItems, false);

                    IExchangeItem[] inputExchangeItems = new IExchangeItem[selectedModel.LinkableComponent.InputExchangeItemCount];
                    for (int i = 0; i < selectedModel.LinkableComponent.InputExchangeItemCount; i++)
                    {
                        inputExchangeItems[i] = selectedModel.LinkableComponent.GetInputExchangeItem(i);
                    }
                    inputExchangeItemSelector.PopulateExchangeItemTree(inputExchangeItems, false);

                    _loadedModelID = selectedModel.ModelID;
                }

                // select model also in comboBox
                // this can cause this method is reentered
                comboBoxModel.SelectedIndex = modelIndex;

                //labelInfo.Text = "Model " + selectedModel.ModelID;

                // show properties of this model
                PropertyGridSelectObject(selectedModel.LinkableComponent);
            }
        }
        /// <summary>
        ///     Creates the array of element IDs in the Matlab environment. Note
        ///     that it pads the IDs to be uniform length since string arrays
        ///     are actually 2d character arrays so all the IDs must be of equal
        ///     length. Note that the IDs have to be trimmed anytime they're
        ///     used.
        /// </summary>
        /// <param name="item"></param>
        private void SetIDArray(IExchangeItem item)
        {
            // build the 1d array to hold the id's
            Array ids = new double[item.ElementSet.ElementCount, 20];
            for (var i = 0; i < item.ElementSet.ElementCount; i++)
            {
                var c = item.ElementSet.GetElementID(i).PadLeft(8, ' ').ToCharArray();

                for (var j = 0; j < c.Length; j++)

                    ids.SetValue(c[j], i, j);
            }

            // set the array
            matlab.PutFullMatrix(GetIDArrayName(item), "base", ids, new double[item.ElementSet.ElementCount, 20]);
        }
示例#17
0
        public override IValueSet GetValues(IExchangeItem querySpecifier)
        {
            if (querySpecifier.TimeSet == null || querySpecifier.TimeSet.Times == null ||
                querySpecifier.TimeSet.Times.Count == 0)
            {
                throw new Exception("Invalid query specifier \"" + querySpecifier.Id +
                                    "\" for in GetValues() call to time decorater " + Id);
            }
            if (ParentOutput.TimeSet == null || ParentOutput.TimeSet.Times == null)
            {
                throw new Exception("Invalid time specifier in decorated output item \"" + ParentOutput.Id +
                                    "\" for in GetValues() call to time decorater " + Id);
            }

            // Determinee query time and currently available time
            double queryTimeAsMJD =
                querySpecifier.TimeSet.Times[querySpecifier.TimeSet.Times.Count - 1].StampAsModifiedJulianDay +
                querySpecifier.TimeSet.Times[querySpecifier.TimeSet.Times.Count - 1].DurationInDays;
            double        availableTimeAsMJD       = Double.NegativeInfinity;
            IList <ITime> decoratedOutputItemTimes = ParentOutput.TimeSet.Times;

            if (decoratedOutputItemTimes.Count > 0)
            {
                availableTimeAsMJD =
                    decoratedOutputItemTimes[decoratedOutputItemTimes.Count - 1].StampAsModifiedJulianDay +
                    decoratedOutputItemTimes[decoratedOutputItemTimes.Count - 1].DurationInDays;
            }

            // Update as far as needed.
            ILinkableComponent linkableComponent = ParentOutput.Component;

            while ((linkableComponent.Status == LinkableComponentStatus.Valid ||
                    linkableComponent.Status == LinkableComponentStatus.Updated) &&
                   availableTimeAsMJD < queryTimeAsMJD)
            {
                linkableComponent.Update();
                // Determine newly available time
                decoratedOutputItemTimes = ParentOutput.TimeSet.Times;
                availableTimeAsMJD       =
                    decoratedOutputItemTimes[decoratedOutputItemTimes.Count - 1].StampAsModifiedJulianDay +
                    decoratedOutputItemTimes[decoratedOutputItemTimes.Count - 1].DurationInDays;
            }

            // Return the values for the required time(s)
            IList <IList <double> > resultValues = new List <IList <double> >();

            if (querySpecifier.TimeSet != null && querySpecifier.TimeSet.Times != null)
            {
                for (int t = 0; t < querySpecifier.TimeSet.Times.Count; t++)
                {
                    resultValues.Add(new List <double>());
                    ITime         queryTime         = querySpecifier.TimeSet.Times[t];
                    List <double> valuesForTimeStep = _buffer.GetValues(queryTime);
                    foreach (double d in valuesForTimeStep)
                    {
                        resultValues[t].Add(d);
                    }
                }
            }
            return(new ValueSet <double>(resultValues));
        }