Exemplo n.º 1
0
        public void CopySelectedComponentsNewOffsetPos(Vector2 offset)
        {
            WorkspaceContainer wc = new WorkspaceContainer(currentProject.Simulation.SelectedComponents);

            Tuple <List <DrawableComponent>, List <DrawableWire> > tup = wc.GenerateDrawables(currentProject.GetAllDescriptions(), offset);

            currentProject.Simulation.AllComponents.AddRange(tup.Item1);
            currentProject.Simulation.AllWires.AddRange(tup.Item2);

            currentProject.Simulation.ClearSelectedComponents();
            currentProject.Simulation.SelectedComponents.AddRange(tup.Item1);
        }
        public void Save(string path, bool saveShellLayout)
        {
            var ws = new WorkspaceContainer();

            //add the assemblies that have a file name
            foreach (var assemblyFile in this.Assemblies.Where(a => a.FullPath != null))
            {
                ws.AssemblyFileReferences.Add(assemblyFile.FilePath);
            }
            //add the assemblies that have no file name, also only the ones that are removable, the nonremovable assemblies are from CShell
            foreach (var assemblyFile in this.Assemblies.Where(a => a.FullPath == null && a.Removable))
            {
                ws.AssemblyNameReferences.Add(assemblyFile.AssemblyName.FullName);
            }

            //save the file settings
            ws.RootFolder = RootFolder;
            ws.Filter     = Filter;

            var serializer = new XmlSerializer(typeof(WorkspaceContainer));
            //using (var textWriter = new StreamWriter(path))
            var settings = new XmlWriterSettings();

            settings.Indent = true;
            //settings.OmitXmlDeclaration = true;
            using (var xmlWriter = XmlWriter.Create(path, settings))
            {
                xmlWriter.WriteStartDocument();
                xmlWriter.WriteStartElement("CShell");
                serializer.Serialize(xmlWriter, ws);

                if (saveShellLayout)
                {
                    //todo: better way of getting the current shell
                    var shell = IoC.Get <IShell>();
                    if (shell != null)
                    {
                        shell.SaveLayout(xmlWriter);
                    }
                }

                xmlWriter.WriteEndElement();
            }
        }
        public bool Load(string path, bool loadShellLayout)
        {
            if (!File.Exists(path))
            {
                return(false);
            }
            var serializer        = new XmlSerializer(typeof(WorkspaceContainer));
            WorkspaceContainer ws = null;

            var settings = new XmlReaderSettings();

            settings.IgnoreWhitespace = true;
            //using (var reader = new StreamReader(path))
            using (var xmlReader = XmlReader.Create(path, settings))
            {
                xmlReader.ReadStartElement();
                ws = (WorkspaceContainer)serializer.Deserialize(xmlReader);

                foreach (var assemblyFile in ws.AssemblyFileReferences)
                {
                    this.Assemblies.Add(assemblyFile);
                }
                foreach (var assemblyName in ws.AssemblyNameReferences)
                {
                    this.Assemblies.Add(new AssemblyReference(new AssemblyName(assemblyName)));
                }

                //restore file settings
                RootFolder = ws.RootFolder ?? "";
                Filter     = ws.Filter ?? "";

                //var es = xmlReader.ReadElementContentAsString();
                if (loadShellLayout)
                {
                    var shell = IoC.Get <IShell>();
                    if (shell != null)
                    {
                        shell.LoadLayout(xmlReader);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 4
0
        public void Save(string path, bool saveShellLayout)
        {
            var ws = new WorkspaceContainer();
            //add the assemblies that have a file name
            foreach (var assemblyFile in this.Assemblies.Where(a=>a.FullPath != null))
            {
                ws.AssemblyFileReferences.Add(assemblyFile.FilePath);
            }
            //add the assemblies that have no file name, also only the ones that are removable, the nonremovable assemblies are from CShell
            foreach (var assemblyFile in this.Assemblies.Where(a => a.FullPath == null && a.Removable))
            {
                ws.AssemblyNameReferences.Add(assemblyFile.AssemblyName.FullName);
            }

            //save the file settings
            ws.RootFolder = RootFolder;
            ws.Filter = Filter;

            var serializer = new XmlSerializer(typeof(WorkspaceContainer));
            //using (var textWriter = new StreamWriter(path))
            var settings = new XmlWriterSettings();
            settings.Indent = true;
            //settings.OmitXmlDeclaration = true;
            using (var xmlWriter = XmlWriter.Create(path, settings))
            {
                xmlWriter.WriteStartDocument();
                xmlWriter.WriteStartElement("CShell");
                serializer.Serialize(xmlWriter, ws);

                if(saveShellLayout)
                {
                    //todo: better way of getting the current shell
                    var shell = IoC.Get<IShell>();
                    if(shell != null)
                        shell.SaveLayout(xmlWriter);
                }

                xmlWriter.WriteEndElement();
            }
        }
Exemplo n.º 5
0
        public WorkspaceUpdateCollector(WorkspaceContainer pContainer, WorkspaceMonitor pMonitor, VideoInfoProvider pVideoInfoProvider)
        {
            Container         = pContainer;
            Monitor           = pMonitor;
            VideoInfoProvider = pVideoInfoProvider;

            Updates = new List <WorkspaceUpdatedEventArgs>();

            _objWaitTimer          = new Timer(2000);
            _objWaitTimer.Elapsed += (sender, e) => {
                _objWaitTimer.Stop();
                lock (Updates) {
                    if (Updates.Count > 0)
                    {
                        var lstCopy = new List <WorkspaceUpdatedEventArgs>(Updates);
                        Updates.Clear();
                        Updated?.Invoke(this, lstCopy);
                    }
                }
            };
            _objWaitTimer.AutoReset = false;
        }
 /// <summary>Creates a n x r matrix B such that B * B^t is a correlation matrix and "near" to the specified symmetric, normalized matrix of dimension n. A rank reduction will apply if r is strict less than n.
 /// </summary>
 /// <param name="rawCorrelationMatrix">The symmetric, normalized matrix where to find the 'nearest' correlation matrix.</param>
 /// <param name="state">The state of the operation in its <see cref="PseudoSqrtMatrixDecomposer.State"/> representation (output).</param>
 /// <param name="outputEntries">This argument will be used to store the matrix entries of the resulting matrix B, i.e. the return value array points to this array if != <c>null</c>; otherwise a memory allocation will be done.</param>
 /// <param name="worksspaceContainer">A specific <see cref="PseudoSqrtMatrixDecomposer.WorkspaceContainer"/> object to reduce memory allocation; ignored if <c>null</c>.</param>
 /// <param name="triangularMatrixType">A value indicating which part of <paramref name="rawCorrelationMatrix"/> to take into account.</param>
 /// <returns>A <see cref="DenseMatrix"/> object that represents a matrix B such that B * B^t is the "nearest" correlation matrix with respect to <paramref name="rawCorrelationMatrix"/>.</returns>
 /// <remarks>In general the return object does <b>not</b> represents the pseudo-root of <paramref name="rawCorrelationMatrix"/>, i.e. output of the Cholesky decomposition.
 /// <para>The parameters <paramref name="outputEntries"/>, <paramref name="worksspaceContainer"/> allows to avoid memory allocation and to re-use arrays if the calculation of correlation matrices will be done often.</para></remarks>
 public abstract DenseMatrix Create(DenseMatrix rawCorrelationMatrix, out State state, double[] outputEntries = null, WorkspaceContainer worksspaceContainer = null, BLAS.TriangularMatrixType triangularMatrixType = BLAS.TriangularMatrixType.LowerTriangularMatrix);
Exemplo n.º 7
0
        /// <summary>Creates a 'n x r' matrix B such that B * B' is a correlation matrix and 'near' to the specified symmetric, normalized matrix of dimension n. A rank reduction will apply if r is strict less than n.
        /// </summary>
        /// <param name="rawCorrelationMatrix">The symmetric, normalized matrix where to find the 'nearest' correlation matrix.</param>
        /// <param name="state">The state of the operation in its <see cref="PseudoSqrtMatrixDecomposer.State"/> representation (output).</param>
        /// <param name="triangularMatrixType">A value indicating which part of <paramref name="rawCorrelationMatrix"/> to take into account.</param>
        /// <param name="outputEntries">This argument will be used to store the matrix entries of the resulting matrix B, i.e. the return value array points to this array if != <c>null</c>; otherwise a memory allocation will be done.</param>
        /// <param name="worksspaceContainer">A specific <see cref="PseudoSqrtMatrixDecomposer.WorkspaceContainer"/> object to reduce memory allocation; ignored if <c>null</c>.</param>
        /// <returns>A <see cref="DenseMatrix"/> object that represents a matrix B such that B * B' is the 'nearest' correlation matrix with respect to <paramref name="rawCorrelationMatrix"/>.</returns>
        /// <remarks>In general the return object does <b>not</b> represents the pseudo-root of <paramref name="rawCorrelationMatrix"/>, i.e. output of the Cholesky decomposition.
        /// <para>The parameters <paramref name="outputEntries"/>, <paramref name="worksspaceContainer"/> allows to avoid memory allocation and to re-use arrays if the calculation of correlation matrices will be done often.</para></remarks>
        public override DenseMatrix Create(DenseMatrix rawCorrelationMatrix, out State state, double[] outputEntries = null, WorkspaceContainer worksspaceContainer = null, BLAS.TriangularMatrixType triangularMatrixType = BLAS.TriangularMatrixType.LowerTriangularMatrix)
        {
            if (rawCorrelationMatrix.IsQuadratic == false)
            {
                throw new ArgumentException("rawCorrelationMatrix");
            }
            int n = rawCorrelationMatrix.RowCount;

            if ((outputEntries == null) || (outputEntries.Length < n * n))
            {
                outputEntries = new double[n * n];
            }
            var ws = worksspaceContainer as Workspace;

            if ((ws == null) || (ws.Dimension < n))
            {
                ws = new Workspace(n);
            }

            /* calculate an initial value for the EZI approach, i.e. apply the Eigenvalue zeroing (without normalization): */
            int initialRank;

            BLAS.Level1.dcopy(n * n, rawCorrelationMatrix.Data, ws.p);
            f1(n, ws.p, 0, ws, outputEntries, out initialRank);

            var detailDataTables = new List <DataTable>();

            if (InfoOutputDetailLevel.IsAtLeastAsComprehensiveAs(InfoOutputDetailLevel.High))
            {
                detailDataTables.Add(CreateDataTableWithEigenvalues("Eigenvalues.Adjusted[0]", initialRank, ws.eigenValues));
            }

            BLAS.Level3.dgemm(n, n, n, 1.0, outputEntries, outputEntries, 0.0, ws.p, transposeB: BLAS.MatrixTransposeState.Transpose);

            BLAS.Level1.dcopy(n * n, ws.p, ws.q);
            int minNumberOfEigenvaluesToSetZero = n - Math.Min(MaximalRank ?? n, initialRank);

            var a    = 1.0;
            int rank = initialRank;

            for (int k = 1; k < AbortCondition.MaxIterations; k++)
            {
                f1(n, ws.q, minNumberOfEigenvaluesToSetZero, ws, outputEntries, out rank);
                if (InfoOutputDetailLevel.IsAtLeastAsComprehensiveAs(InfoOutputDetailLevel.Full))
                {
                    detailDataTables.Add(CreateDataTableWithEigenvalues(String.Format("Eigenvalues.Adjusted[{0}", k), rank, ws.eigenValues));
                }

                BLAS.Level3.dgemm(n, n, n, 1.0, outputEntries, outputEntries, 0.0, ws.q, transposeB: BLAS.MatrixTransposeState.Transpose);

                /* normalize the correlation matrix, i.e. calculate <q> */
                for (int i = 0; i < n; i++)
                {
                    var t_i = 0.0;
                    for (int j = n - 1; j >= n - rank; j--)
                    {
                        t_i += outputEntries[i + j * n] * outputEntries[i + j * n];
                    }
                    BLAS.Level1.dscal(rank, 1.0 / Math.Sqrt(t_i), outputEntries, -n, i + (n - 1) * n); // [i+j*n] *= 1/Math.Sqrt(t_i) for j = n-1, ..., n-rank
                }
                BLAS.Level3.dgemm(n, n, n, 1.0, outputEntries, outputEntries, 0.0, ws.qNormalized, transposeB: BLAS.MatrixTransposeState.Transpose);

                if (AbortCondition.IsSatisfied(n, ws.p, ws.q, ws.qNormalized, ref a) == true)
                {
                    /* The eigenvalues are in ascending order. Thefore the first (and not last) 'rank' columns of the eigenvectors are not required. Therefore we swap the relevant part: */
                    BLAS.Level1.dswap(n * rank, outputEntries, 1, outputEntries, 1, n * (n - rank), 0);
                    state = State.Create(rank, new InfoOutputProperty[] { InfoOutputProperty.Create("Eigenvalues set to 0.0", n - rank) }, detailDataTables, iterationsNeeded: k, infoOutputDetailLevel: InfoOutputDetailLevel);
                    return(new DenseMatrix(n, rank, outputEntries));
                }

                BLAS.Level1.dcopy(n * n, ws.q, ws.p); // set p := q
                for (int j = 0; j < n; j++)
                {
                    ws.q[j * n + j] = 1.0;
                }
            }

            /* The eigenvalues are in ascending order. Thefore the first (and not last) 'rank' columns of the eigenvectors are not required. Therefore we swap the relevant part: */
            BLAS.Level1.dswap(n * rank, outputEntries, 1, outputEntries, 1, n * (n - rank), 0);

            state = State.Create(rank, new InfoOutputProperty[] { InfoOutputProperty.Create("Number of EigenValues set to 0.0", n - rank) }, detailDataTables, AbortCondition.MaxIterations, infoOutputDetailLevel: InfoOutputDetailLevel);
            return(new DenseMatrix(n, rank, outputEntries));
        }