Example #1
0
        /// <summary>
        /// Given the Model Objects, data objects and the vector(vIndep) in which '1' represent an independent variables , this function creates
        /// a subprocess after performing the computational proces modelling
        /// </summary>
        /// <param name="name"></param>
        /// <param name="components"></param>
        /// <param name="dataObjects"></param>
        /// <param name="independent"></param>
        /// <returns></returns>
        public static Workflow ScheduleWorkflow(string name, string description, List <Data> inputs, List <Data> outputs, List <WorkflowComponent> components)
        {
            explorationWatch.Restart();
            List <Data> data = components.GetAllData(inputs, out int[] independent);

            // Incidence matrices for the workfow
            IncidenceMatrix IMf = LibishMatrixCalculators.GetIncidenceMatrix(components, data);
            IncidenceMatrix IMi = VariableFlowModelling(IMf, independent);
            // Model-based DSM
            DesignStructureMatrix DSM = IMMtoDSM(IMi);
            // Locates SCCs
            List <Cluster> clusters = Decompose(DSM);
            // SCC-based incidence matrix
            IncidenceMatrix IMU = CreateUpMatrix(IMi, clusters);
            // SCC-based DSM
            DesignStructureMatrix DSMU = IMMtoDSM(IMU);
            // Orders the models, so there is only feed-forward
            List <int> order = SequenceDsm(DSMU);

            // Creates the workflows for the reversed models
            WorkflowComponent[] processedComponents = CreateReversedModels(IMi, IMf, components, data, clusters, name);
            // Creates the workflows for the SCCs (default order)
            List <WorkflowComponent> clusteredComponents = CreateSCCs(processedComponents, clusters, data, name);
            // Applies the order (vDsmArr) to the models
            List <WorkflowComponent> scheduledComponents = Schedule(clusteredComponents, order);
            // Enables dependency analysis
            var dependencyAnalysis = new MatrixBasedDependencyAnalysis(processedComponents);

            return(new Workflow(name, description, inputs, outputs, components, scheduledComponents)
            {
                DependencyAnalysis = dependencyAnalysis
            });
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="models"></param>
        /// <param name="dataObjects"></param>
        /// <returns></returns>
        public static IncidenceMatrix GetIncidenceMatrix(List <WorkflowComponent> models, List <Data> dataObjects)
        {
            if (models.Count > 0 && dataObjects.Count > 0)
            {
                IncidenceMatrix IM = IncidenceMatrix.Build.Dense(models.Count, dataObjects.Count);

                // Initialiase dictionary set with variable names and indices
                Dictionary <string, int> dataIndices = GetDataIndices(dataObjects);

                for (int m = 0; m < models.Count; m++)
                {
                    IEnumerable <string> inputNames = models[m].ModelDataInputs.Select(d => d.Id);
                    foreach (string name in inputNames)
                    {
                        IM[m, dataIndices[name]] = LibishScheduler.IN;
                    }

                    IEnumerable <string> outputNames = models[m].ModelDataOutputs.Select(d => d.Id);
                    foreach (string name in outputNames)
                    {
                        IM[m, dataIndices[name]] = LibishScheduler.OUT;
                    }
                }

                return(IM);
            }
            else
            {
                return(null);
            }
        }
Example #3
0
        private static DataArray <string> IncidenceMatrixWithCalcuationsToDataArray(IncidenceMatrix <Goal> matrix)
        {
            var matrixLength            = matrix.Variables.Length;
            var dataArray               = new DataArray <string>(matrixLength + 3, matrixLength + 3);
            var data                    = matrix.ToInt32Array();
            var numberOfAncestors       = matrix.GetNumberOfAncestorsForEachVariable().Values.ToArray();
            var numberOfDescendants     = matrix.GetNumberOfDescendantsForEachVariable().Values.ToArray();
            var prioritiesOfAncestors   = matrix.GetPrioritiesByAncestorsForEachVariable().Values.ToArray();
            var prioritiesOfDescendants = matrix.GetPrioritiesByDescendantsForEachVariable().Values.ToArray();

            for (int i = 1; i < matrixLength + 1; i++)
            {
                dataArray[i][0] = dataArray[0][i] = matrix.Variables[i - 1].Index.ToString();
                for (int j = 1; j < matrixLength + 1; j++)
                {
                    dataArray[i][j] = data[i - 1, j - 1].ToString();
                }
                dataArray[matrixLength + 1][i] = numberOfDescendants[i - 1].ToString();
                dataArray[i][matrixLength + 1] = numberOfAncestors[i - 1].ToString();
                dataArray[matrixLength + 1][matrixLength + 1] = numberOfDescendants.Sum().ToString();
                dataArray[matrixLength + 2][i] = prioritiesOfDescendants[i - 1].ToString();
                dataArray[i][matrixLength + 2] = prioritiesOfAncestors[i - 1].ToString();
            }
            return(dataArray);
        }
        private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            if (this.IsLoaded)
            {
                Slider slider = (Slider)sender;

                lblVertexCount.Content = (int)slider.Value;

                ResetLines();
                adjMat  = new AdjMatrix((int)slider.Value);
                incMat  = new IncidenceMatrix((int)slider.Value);
                adjList = new AdjList((int)vertsSlider.Value);

                if (vertsUI.Count == 0)
                {
                    return;
                }

                for (int i = 0; i < (int)slider.Value; i++)
                {
                    vertsUI[i].Visibility = Visibility.Visible;
                }
                for (int i = (int)slider.Value; i < vertsUI.Count; i++)
                {
                    vertsUI[i].Visibility = Visibility.Hidden;
                }
            }
        }
 public IncidenceMatrixInputViewModel()
 {
     GraphContext.Instance.Add(this);
     _incidenceMatrix = new IncidenceMatrix(Vertices, Edges);
     Matrix           = _incidenceMatrix.ToMatrix().ToReferenceMatrix();
     OnPropertyChanged(nameof(Matrix));
 }
Example #6
0
 public BusinessSystem()
 {
     KeyAreas             = new List <string>();
     FunctionalAreas      = new Scope();
     AmbientAreas         = new Scope();
     GoalsIncidenceMatrix = new IncidenceMatrix <Goal>(new HashSet <Goal>());
 }
Example #7
0
        /// <summary>
        /// Performs the varaible flow modelling given the foundation IM and the vector representing the independent variable.
        /// </summary>
        /// <param name="IMf"></param>
        /// <param name="independent"></param>
        /// <returns></returns>
        private static IncidenceMatrix VariableFlowModelling(IncidenceMatrix IMf, int[] independent)
        {
            IncidenceMatrix[] IMSet = AllWorkflows(IMf, independent);
            int LeastModified       = LibishScheduler.LeastModified(IMSet, IMf);

            return(IMSet[LeastModified]);
            // code for genetic algorithm
        }
Example #8
0
        public static void SetOutput(this IncidenceMatrix IM, int variable, IncidenceMatrix IMf)
        {
            Cluster locs = IMf.Column(variable).FindLocations(OUT);

            if (locs.Count > 0)
            {
                int r = locs.First();
                IM[r, variable] = OUT;                 // Asign variable as output of the firs model that has it as a default output
            }
            IM.MultiplyColumn(variable, IN);
        }
Example #9
0
        public static IncidenceMatrix GetIncidenceMatrixFromPlaceDictionary(SortedDictionary <int, Place> data)
        {
            if (data.Count == 0)
            {
                return(null);
            }
            IncidenceMatrix preIncidenceMatrix  = GetPreIncidenceMatrixFromPlaceDictionary(data);
            IncidenceMatrix postIncidenceMatrix = GetPostIncidenceMatrixFromPlaceDictionary(data);

            return(postIncidenceMatrix - preIncidenceMatrix);
        }
Example #10
0
        public static bool CompareAssigned(this IncidenceMatrix M1, IncidenceMatrix M2, int row)
        {
            for (int i = 0; i < M1.ColumnCount; i++)
            {
                if (M1[row, i] != M2[row, i] && M2[row, i] != ANY)
                {
                    return(false);
                }
            }

            return(true);
        }
Example #11
0
        private static List <int> ModelsInSCCFromIMM(IncidenceMatrix IM)
        {
            var modelsInSCC = new List <int>();

            for (int r = 0; r < IM.RowCount; r++)
            {
                if (FindValueInArray(IM.Row(r).ToArray(), ANY))
                {
                    modelsInSCC.Add(r);
                }
            }
            return(modelsInSCC);
        }
Example #12
0
        /// <summary>
        /// Given a matrix incm, given an intial completely populated real matrix incmreal
        /// changeval are those rows of incm where the models associated varaible are
        /// modified
        /// </summary>
        /// <param name="IMi"></param>
        /// <param name="IMf"></param>
        /// <returns></returns>
        private static List <int> FindNotAssignedModels(IncidenceMatrix IMi, IncidenceMatrix IMf)
        {
            var notAssignedRows = new List <int>();

            for (int model = 0; model < IMi.RowCount; model++)
            {
                if (IMi.IsModelUnassigned(model))
                {
                    notAssignedRows.Add(model);
                }
            }
            return(notAssignedRows);
        }
Example #13
0
        /// <summary>
        /// Given a matrix incm, given an intial completely populated real matrix incmreal
        /// changeval are those rows of incm where the models associated varaible are
        /// modified
        /// </summary>
        /// <param name="IMi"></param>
        /// <param name="IMf"></param>
        /// <returns></returns>
        private static List <int> FindReversedModels(IncidenceMatrix IMi, IncidenceMatrix IMf)
        {
            var reversedRows = new List <int>();

            for (int model = 0; model < IMi.RowCount; model++)
            {
                if (IMi.IsModelReversed(model, IMf))
                {
                    reversedRows.Add(model);
                }
            }
            return(reversedRows);
        }
Example #14
0
        public static Marking GetInitialMarkingFromPlaceDictionary(SortedDictionary <int, Place> data)
        {
            if (data.Count == 0)
            {
                return(null);
            }
            IncidenceMatrix preIncidenceMatrix  = GetPreIncidenceMatrixFromPlaceDictionary(data);
            IncidenceMatrix postIncidenceMatrix = GetPostIncidenceMatrixFromPlaceDictionary(data);
            List <int>      initialMarkingData  = new List <int>();

            foreach (Place p in data.Values.ToList())
            {
                initialMarkingData.Add(p.InitialTokenNum);
            }
            return(new Marking(0, new ColumnVector(initialMarkingData), preIncidenceMatrix, postIncidenceMatrix));
        }
Example #15
0
        private void EnsureValidated()
        {
            if (!Invalidated)
            {
                return;
            }

            IncidenceMatrix.Clear();
            foreach (var sample in Samples)
            {
                var point = new BinaryPoint(ColorToPoint(sample.Color), sample.Polarity);
                IncidenceMatrix.Add(point);
            }

            Invalidated = false;
        }
Example #16
0
        /// <summary>
        /// This is the first step of incidence matrix method. This function performs the operation described in chapter3.2.1 in [1]
        /// </summary>
        /// <param name="IM"></param>
        /// <param name="Noutvalr"></param>
        /// <param name="Noutvalc"></param>
        /// <param name="Activat"></param>
        private static void IncidenceMatrixFirstStep(IncidenceMatrix IM, double[] Noutvalr, double[] Noutvalc, bool Activat)
        {
            IncidenceMatrix IMstart;

            do
            {
                IMstart = IncidenceMatrix.Build.DenseOfMatrix(IM);
                var locations = IM.FindLocations(ANY);
                foreach ((int row, int col) in locations)
                {
                    double currentValr = IM.Row(row).MultiplyNonZeroVector();
                    double currentValc = IM.Column(col).MultiplyNonZeroVector();
                    // Coefficients in equations (1) to (4) in reference [1]
                    double Cvalr = Noutvalr[row] / currentValr;
                    double Cvalc = Noutvalc[col] / currentValc;
                    //checking for rows
                    double R2 = Log(Cvalr) / Log(IN);
                    double R3 = Log(Cvalr) / Log(OUT);
                    double C2 = Log(Cvalc) / Log(IN);
                    double C3 = Log(Cvalc) / Log(OUT);

                    if (IsInteger(R2) && !IsInteger(C3))                     // D1 in Fig. 1
                    {
                        IM[row, col] = IN;
                    }
                    else if (IsInteger(R3) && !IsInteger(C2))                     // D2 in Fig. 1
                    {
                        IM[row, col] = OUT;
                    }
                    else if (IsInteger(C2) && !IsInteger(R3))                     // D3 in Fig. 1
                    {
                        IM[row, col] = IN;
                    }
                    else if (IsInteger(C3) && !IsInteger(R2))
                    {
                        if (!Activat && (IM.Column(col).FindAnyValue() > 1))
                        {
                            IM[row, col] = OUT;
                        }
                        else if (Activat)
                        {
                            IM[row, col] = OUT;
                        }
                    }
                }
            } while (!IMstart.Equals(IM));
        }
Example #17
0
        /// <summary>
        /// creates the new incidence matrix based on the SCCs. SCCs are clustered in the new DSM in a single row.
        /// </summary>
        /// <param name="IM"></param>
        /// <param name="clusters"></param>
        /// <returns></returns>
        private static IncidenceMatrix CreateUpMatrix(IncidenceMatrix IM, List <Cluster> clusters)
        {
            IncidenceMatrix imMatrixU = IncidenceMatrix.Build.Dense(clusters.Count, IM.ColumnCount);

            for (int r = 0; r < clusters.Count; r++)
            {
                Cluster cluster = clusters[r];
                if (cluster.Count == 1)
                {
                    imMatrixU.SetRow(r, IM.Row(cluster[0]));
                }
                else
                {
                    IncidenceMatrix imMatrixT = IncidenceMatrix.Build.Dense(cluster.Count, IM.ColumnCount);
                    int             nvC       = 0;
                    foreach (int nRow in cluster)
                    {
                        imMatrixT.SetRow(nvC, IM.Row(nRow));
                        nvC++;
                    }
                    for (int c = 0; c < IM.ColumnCount; c++)
                    {
                        Vector <double> column = imMatrixT.Column(c);
                        int             Nin    = column.FindValue(IN);
                        int             Nout   = column.FindValue(OUT);
                        if (Nin > 0 && Nout > 0)
                        {
                            imMatrixU[r, c] = OUT;
                        }
                        else if (Nout > 0)
                        {
                            imMatrixU[r, c] = OUT;
                        }
                        else if (Nin > 0)
                        {
                            imMatrixU[r, c] = IN;
                        }
                        else
                        {
                            imMatrixU[r, c] = NOTHING;
                        }
                    }
                }
            }
            return(imMatrixU);
        }
Example #18
0
        /// <summary>
        /// Converts an incidence matrix to design structure matrix.
        /// </summary>
        /// <param name="IM"></param>
        /// <returns></returns>
        public static DesignStructureMatrix IncidenceMatrixToDesignStructureMatrix(IncidenceMatrix IM)
        {
            DesignStructureMatrix DSM       = IncidenceMatrix.Build.DenseIdentity(IM.RowCount, IM.RowCount);
            List <(int i, int j)> locRowCol = IM.FindLocations(LibishScheduler.OUT);

            foreach ((int row, int col) in locRowCol)
            {
                List <int> inputLocaltions = IM.Column(col).FindLocations(LibishScheduler.IN);
                if (inputLocaltions != null)
                {
                    foreach (int i in inputLocaltions)
                    {
                        DSM[row, i] = LibishScheduler.ANY;
                    }
                }
            }
            return(DSM);
        }
        public MainWindow()
        {
            InitializeComponent();

            adjMat  = new AdjMatrix((int)vertsSlider.Value);
            incMat  = new IncidenceMatrix((int)vertsSlider.Value);
            adjList = new AdjList((int)vertsSlider.Value);

            vertsUI.Add(v1);
            vertsUI.Add(v2);
            vertsUI.Add(v3);
            vertsUI.Add(v4);
            vertsUI.Add(v5);
            vertsUI.Add(v6);
            vertsUI.Add(v7);
            vertsUI.Add(v8);
            vertsUI.Add(v9);
            vertsUI.Add(v10);
        }
Example #20
0
        private static int FindNReversed(IncidenceMatrix IMdef, IncidenceMatrix IM)
        {
            int noOfRevModels = 0;

            for (int i = 0; i < IM.RowCount; i++)
            {
                for (int j = 0; j < IM.ColumnCount; j++)
                {
                    int defaultCellValue = Convert.ToInt32(IMdef[i, j]);
                    int revInciValue     = Convert.ToInt32(IM[i, j]);
                    if (revInciValue != NOTHING && defaultCellValue != revInciValue && revInciValue != ANY)
                    {
                        // therefore model i, must be reversed
                        noOfRevModels++;
                        break;
                    }
                }
            }
            return(noOfRevModels);
        }
Example #21
0
        /// <summary>
        /// This function identifies the Modified models (from imMatrixi and imMatrif) in the modelObjects, then creates a 'modified model subprocess' for each modified model,
        /// and therafter combines it with other models in the modelObjects and return it in a object array
        /// </summary>
        /// <param name="IMi"></param>
        /// <param name="IMf"></param>
        /// <param name="components"></param>
        /// <param name="data"></param>
        /// <param name="clusters"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private static WorkflowComponent[] CreateReversedModels(IncidenceMatrix IMi, IncidenceMatrix IMf, List <WorkflowComponent> components, List <Data> data, List <Cluster> clusters, string name)
        {
            var processedComponents = new WorkflowComponent[IMf.RowCount];

            for (int r = 0; r < IMi.RowCount; r++)
            {
                WorkflowComponent component = components[r];
                Vector <double>   row       = IMi.Row(r);
                if (!IMf.Row(r).CompareAssigned(row))
                {
                    List <int> inputIndices  = row.FindLocations(IN);
                    List <int> outputIndices = row.FindLocations(OUT);
                    var        inputs        = inputIndices.Select(i => data[i]).ToList();
                    var        outputs       = outputIndices.Select(i => data[i]).ToList();

                    if (component is Model model)
                    {
                        processedComponents[r] = model.Reverse(inputs, outputs);
                    }
                    else if (component is Workflow workflow)
                    {
                        var opts = new NewtonOptions()
                        {
                            MaxIterations = 20, DerivativeStep = new double[] { 0.01 }
                        };
                        var solver = new NewtonSolver(opts);
                        processedComponents[r] = new WorkflowGlobal($"{name}#GlobalWorkflow#{workflow.Name}", "", inputs, outputs, workflow.Components, workflow.Components, new List <ISolver>()
                        {
                            solver
                        });
                    }
                }
                else
                {
                    processedComponents[r] = components[r];
                }
            }
            return(processedComponents);
        }
Example #22
0
        public static IncidenceMatrix GetPostIncidenceMatrixFromPlaceDictionary(SortedDictionary <int, Place> data)
        {
            if (data.Count == 0)
            {
                return(null);
            }
            SortedDictionary <int, Place> newData = new SortedDictionary <int, Place>(data);

            newData = FillWithOthersTransition(newData);

            List <List <int> > list = new List <List <int> >();

            foreach (KeyValuePair <int, Place> item in newData)
            {
                list.Add(item.Value.PreTransitions.Values.ToList());
            }
            IncidenceMatrix postIncidenceMatrix = new IncidenceMatrix(newData.Keys.ToList(),
                                                                      newData.First().Value.PreTransitions.Keys.ToList(),
                                                                      list);

            return(postIncidenceMatrix);
        }
Example #23
0
        /// <summary>
        /// This function adds additional varaibles as indpendent varaibles. This is done when the system is underdetermined and
        /// additional variables are required to solve it.
        /// </summary>
        /// <param name="IM"></param>
        /// <param name="Noutvalr"></param>
        /// <param name="Noutvalc"></param>
        private static void FillAsInput(IncidenceMatrix IM, double[] Noutvalr, double[] Noutvalc)
        {
            List <(int i, int j)> locations = IM.FindLocations(ANY);

            foreach ((int row, int col) in locations)
            {
                //% fills the ANYs with IN if IN has to be put in row and in column
                //% this make the variable in the column to be an input
                double currentValr = IM.Row(row).MultiplyNonZeroVector();
                double currentValc = IM.Column(col).MultiplyNonZeroVector();
                // Coefficients in equations (1) to (4) in reference [1]
                double Cvalr = Noutvalr[row] / currentValr;
                double Cvalc = Noutvalc[col] / currentValc;
                //checking for rows
                double R2 = Log(Cvalr) / Log(IN);
                double C3 = Log(Cvalc) / Log(OUT);

                if (IsInteger(R2) && IsInteger(C3))                 // D1 in Fig. 1
                {
                    IM[row, col] = IN;
                }
            }
        }
        public IncWindow()
        {
            InitializeComponent();

            IncidenceMatrix incMat = MainWindow.incMat;

            for (int i = 0; i < incMat.noOfVertices; i++)
            {
                Label tempLabel = new Label();
                tempLabel.Content = "v" + (i + 1);
                tempLabel.Margin  = new Thickness(10, ((i + 1) * HEIGHTDIFF) + 10, 0, 0);

                matGrid.Children.Add(tempLabel);
            }

            for (int i = 0; i < incMat.incidenceMatrix[0].Count; i++)
            {
                Label tempLabel = new Label();
                tempLabel.Content = (char)('a' + i);
                tempLabel.Margin  = new Thickness(((i + 1) * WIDTHDIFF) + 10, 10, 0, 0);

                matGrid.Children.Add(tempLabel);
            }

            for (int i = 0; i < incMat.noOfVertices; i++)
            {
                for (int j = 0; j < incMat.incidenceMatrix[i].Count; j++)
                {
                    Label tempLabel = new Label();
                    tempLabel.Content = incMat.incidenceMatrix[i][j];
                    tempLabel.Margin  = new Thickness(((j + 1) * WIDTHDIFF) + 10, ((i + 1) * HEIGHTDIFF) + 10, 0, 0);

                    matGrid.Children.Add(tempLabel);
                }
            }
        }
Example #25
0
 /// <summary>
 /// replaces values in vMatrix whic are %lt; vWhat with vWith
 /// </summary>
 /// <param name="vMatrix"></param>
 /// <param name="vWhat"></param>
 /// <param name="vWith"></param>
 public static void ReplaceLessthanWith(this IncidenceMatrix M, int limit, int value) => M.MapInplace(d => (d < limit) ? value : d);
Example #26
0
 public static bool IsModelUnassigned(this IncidenceMatrix IM, int model) => IM.Row(model).FindValue(ANY) > 0;
Example #27
0
 public static bool IsModelReversed(this IncidenceMatrix IM, int model, IncidenceMatrix IMf) => !LibishMatrixCalculators.CompareAssigned(IMf, IM, model);
Example #28
0
 public static void SetInput(this IncidenceMatrix IM, int variable) => IM.MultiplyColumn(variable, IN);
Example #29
0
 public static int NOutputs(this IncidenceMatrix IM, int model) => IM.Row(model).FindValue(OUT);
Example #30
0
 public static int NInputs(this IncidenceMatrix IM, int model) => IM.Row(model).FindValue(IN);