Esempio n. 1
0
        /* This is APPLY for the rule entitled: beginning rule3 */
        public designGraph gearspeedbegrule3(designGraph Lmapping, designGraph host, designGraph Rmapping, double[] parameters)
        {
            double gearspeedrule3 = Lmapping.nodes[1].localVariables[1];
            double radius1rule3 = Lmapping.nodes[1].localVariables[3];
            double teeth1rule3 = Lmapping.nodes[1].localVariables[2];
            /* obtaining values for old properties */

            Rmapping.nodes[1].localVariables[0] = 0.0;
            Rmapping.nodes[1].localVariables[1] = gearspeedrule3;
            Rmapping.nodes[1].localVariables[2] =  teeth1rule3;
            Rmapping.nodes[1].localVariables[3] = radius1rule3;
            /* setting old gear properties*/

            Rmapping.nodes[0].localVariables[0] = gearspeedrule3;
            /* setting shaft on right properties*/

            double teeth2rule3 = Rmapping.nodes[2].localVariables[2];
            double radius2rule3 = Rmapping.nodes[2].localVariables[3];
            /*obtaining new gear properties from right*/

            Rmapping.nodes[2].localVariables[0] = -(teeth1rule3/teeth2rule3);
            Rmapping.nodes[2].localVariables[1] = -((gearspeedrule3 * radius1rule3)/radius2rule3);
            /* setting new properties with calculations*/
            /* put the mechanical advantage into the 0 slot under the gear label*/
            /*slot 0- MA, slot 1 - speed, slot 2 - teeth(catalog), slot 3 - radius(catalog)*/
            return host;
        }
Esempio n. 2
0
        public designGraph copy()
        {
            /* at times we want to copy a graph and not refer to the same objects. This happens mainly
             * (rather initially what inspired this function) when the seed graph is copied into a candidate.*/
            int         toIndex, fromIndex;
            designGraph copyOfGraph = new designGraph();

            copyOfGraph.name = name;
            foreach (string label in globalLabels)
            {
                copyOfGraph.globalLabels.Add(label.ToString());
            }
            foreach (double v in globalVariables)
            {
                copyOfGraph.globalVariables.Add(v);
            }
            foreach (node origNode in nodes)
            {
                copyOfGraph.nodes.Add(origNode.copy());
            }
            foreach (arc origArc in arcs)
            {
                arc copyOfArc = origArc.copy();
                toIndex   = nodes.FindIndex(delegate(node a) { return(a == origArc.To); });
                fromIndex = nodes.FindIndex(delegate(node b) { return(b == origArc.From); });
                copyOfGraph.addArc(copyOfArc, fromIndex, toIndex);
            }
            return(copyOfGraph);
        }
Esempio n. 3
0
        /* This is APPLY for the rule entitled: gearshaftgear */
        public designGraph gearspeedgsg(designGraph Lmapping, designGraph host, designGraph Rmapping, double[] parameters)
        {
            double gearmagsg = Lmapping.nodes[0].localVariables[0];
            double gearspeed1gsg = Lmapping.nodes[0].localVariables[1];
            double radius1gsg = Lmapping.nodes[0].localVariables[3];
            double teeth1gsg = Lmapping.nodes[0].localVariables[2];
            /* obtaining values for old properties */

            Rmapping.nodes[1].localVariables[0] = gearspeed1gsg;
            /* setting shaft on right properties*/

            Rmapping.nodes[0].localVariables[1] = gearspeed1gsg;
            Rmapping.nodes[0].localVariables[2] = teeth1gsg;
            Rmapping.nodes[0].localVariables[3] = radius1gsg;
            Rmapping.nodes[0].localVariables[0] = gearmagsg;
            /* setting old gear properties*/

            double teeth2gsg = Rmapping.nodes[4].localVariables[2];
            double radius2gsg = Rmapping.nodes[4].localVariables[3];
            /*obtaining new gear properties from right*/

            Rmapping.nodes[4].localVariables[0] = (-(teeth1gsg/teeth2gsg)) * gearmagsg;
            Rmapping.nodes[4].localVariables[1] = -((gearspeed1gsg * radius1gsg)/radius2gsg);
            /* setting new properties with calculations*/

            return host;
        }
Esempio n. 4
0
 public graphDisplay()
 {
     InitializeComponent();
     this.MdiParent = Program.main;
     graphControl1.LoadLibraries();
     graph1 = new designGraph();
 }
Esempio n. 5
0
        /// <summary>
        /// Creates a random graph that takes two parameters: the number of nodes,
        /// and the average degree. Note: that there is no guarantee that the graph
        /// will be connected.
        /// </summary>
        /// <param name = "numNodes">The number of nodes.</param>
        /// <param name = "aveDegree">The average degree.</param>
        /// <returns></returns>
        public static designGraph CreateRandomGraph(int numNodes, int aveDegree)
        {
            var randomGraph = new designGraph
            {
                name = "RandomGraph_with_" + numNodes + "_nodes_and_degree_of_" + aveDegree
            };
            var arcProb = (double)aveDegree / (numNodes + 1);
            var rnd     = new Random();

            for (var i = 0; i != numNodes; i++)
            {
                randomGraph.addNode();
            }

            for (var i = 0; i != numNodes; i++)
            {
                for (var j = i + 1; j != numNodes; j++)
                {
                    if ((double)rnd.Next(1000) / 1000 <= arcProb)
                    {
                        randomGraph.addArc(randomGraph.nodes[i], randomGraph.nodes[j]);
                    }
                }
            }
            return(randomGraph);
        }
Esempio n. 6
0
 public static void saveGraphToXml
     (string filename, Netron.GraphLib.UI.GraphControl graphControl1, designGraph graph1)
 {
     graph1.updateFromGraphControl(graphControl1);
     graph1.checkForRepeatNames();
     saveGraphToXml(filename, graph1);
 }
Esempio n. 7
0
        /* This is the recognize function called within the RCA generation. It is
         * fairly straightforward method that basically invokes the more complex
         * recognize function for each rule within it, and returns a list of
         * options. */
        public List <option> recognize(designGraph host)
        {
            List <designGraph> locations = new List <designGraph>();
            List <option>      options   = new List <option>();

            if (rules.Count == 0)
            {
                return(options);
            }
            for (int i = 0; i != rules.Count; i++)
            {
                locations = rules[i].recognize(host);
                if (locations.Count > 0)
                {
                    foreach (designGraph a in locations)
                    {
                        options.Add(new option());
                        options[options.Count - 1].ruleSetIndex = this.ruleSetIndex;
                        options[options.Count - 1].ruleNumber   = i + 1;
                        options[options.Count - 1].rule         = rules[i];
                        options[options.Count - 1].location     = a;
                        if (this.choiceMethod == choiceMethods.Automatic)
                        {
                            return(options);
                        }

                        /* this is merely for efficiency - once we get one valid option for
                         * an Automatic ruleset we can exit and invoke that option. */
                    }
                }
            }
            return(options);
        }
 public static void saveGraphToXml
     (string filename, Netron.GraphLib.UI.GraphControl graphControl1, designGraph graph1)
 {
     graph1.updateFromGraphControl(graphControl1);
     graph1.checkForRepeatNames();
     saveGraphToXml(filename, graph1);
 }
Esempio n. 9
0
        /// <summary>
        ///   Is the arc a free arc from this grammar rule?
        /// </summary>
        /// <param name = "a">A.</param>
        /// <param name = "host">The host.</param>
        /// <param name = "freeEndIdentifier">The free end identifier.</param>
        /// <param name = "neighborNode">The neighbor node.</param>
        /// <returns></returns>
        public static Boolean arcIsFree(arc a, designGraph host, out sbyte freeEndIdentifier, out node neighborNode)
        {
            if (a.From != null && a.To != null &&
                !host.nodes.Contains(a.From) && !host.nodes.Contains(a.To))
            {
                freeEndIdentifier = 0;

                /* if the nodes on either end of the freeArc are pointing to previous nodes
                 * that were deleted in the first pushout then neighborNode is null (and as
                 * a result any rules using the neighborNodeLabel will not apply) and the
                 * freeEndIdentifier is zero. */
                neighborNode = null;
                return(true);
            }
            if (a.From != null && !host.nodes.Contains(a.From))
            {
                freeEndIdentifier = -1;
                /* freeEndIdentifier set to -1 means that the From end of the arc must be the free end.*/
                neighborNode = a.To;
                return(true);
            }
            if (a.To != null && !host.nodes.Contains(a.To))
            {
                freeEndIdentifier = +1;
                /* freeEndIdentifier set to +1 means that the To end of the arc must be the free end.*/
                neighborNode = a.From;
                return(true);
            }

            /* else, the arc is not a free arc after all and we simply break out
             * of this loop and try the next arc. */
            freeEndIdentifier = 0;
            neighborNode      = null;
            return(false);
        }
Esempio n. 10
0
 private void showNodeArcProperties(PropertyBag shapeProps, designGraph graph)
 {
     this.nodeArcProps.Enabled = true;
     this.propertiesTabControl.SelectedIndex = 0;
     try
     {
         if ((shapeProps.Owner.GetType()) == (typeof(Connection)))
         {
             arc temparc = graph.arcs.Find(delegate(arc b)
                 { return (b.displayShape == shapeProps.Owner); });
             if (temparc.Bag == null) temparc.initPropertiesBag();
             this.nodeArcProps.SelectedObject = temparc.Bag;
         }
         else
         {
             node tempnode = graph.nodes.Find(delegate(node b)
                 { return (b.displayShape == shapeProps.Owner); });
             if (tempnode.Bag == null) tempnode.initPropertiesBag();
             this.nodeArcProps.SelectedObject = tempnode.Bag;
         }
     }
     catch
     {
         this.nodeArcProps.Enabled = false;
         this.propertiesTabControl.SelectedIndex = 1;
     }
 }
Esempio n. 11
0
        public static designGraph openGraphFromXml(string filename)
        {
            StreamReader graphReader    = null;
            designGraph  newDesignGraph = null;

            try
            {
                graphReader = new StreamReader(filename);
                XmlSerializer graphDeserializer = new XmlSerializer(typeof(designGraph));
                newDesignGraph = (designGraph)graphDeserializer.Deserialize(graphReader);
                SearchIO.output(Path.GetFileName(filename) + " successfully loaded.");
                newDesignGraph.internallyConnectGraph();
                if (newDesignGraph.name == null)
                {
                    newDesignGraph.name = Path.GetFileName(filename).TrimEnd(new char[] { '.', 'x', 'm', 'l' });
                }
            }
            catch (Exception ioe)
            { SearchIO.output("Error Opening Graph: " + ioe.ToString()); }
            finally
            {
                if (graphReader != null)
                {
                    graphReader.Close();
                }
            }
            return(newDesignGraph);
        }
Esempio n. 12
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "candidate" /> class.
 /// </summary>
 /// <param name = "_graph">The _graph.</param>
 /// <param name = "numRuleSets">The num rule sets.</param>
 public candidate(designGraph _graph, int numRuleSets)
 {
     graph = _graph;
     for (var i = 0; i != numRuleSets; i++)
     {
         GenerationStatus.Add(GenerationStatuses.Unspecified);
     }
 }
Esempio n. 13
0
 /* if true then all arcs between the nodes in L must be in host and no more 
  * - again not a proper SUBSET
  * if false then proper subset.
  * this following function is the only to use induced and is only called early
  * in the Location Found case, and only then when induced is true. As its name implies it 
  * simply checks to see if there are any arcs in the host between the nodes recognized. */
 private Boolean noOtherArcsInHost(designGraph host, List<node> locatedNodes, List<arc> locatedArcs)
 {
     foreach (arc a in host.arcs)
     {
         if (!locatedArcs.Contains(a) && locatedNodes.Contains(a.From) && locatedNodes.Contains(a.To))
             return false;
     }
     return true;
 }
Esempio n. 14
0
 public graphDisplay(designGraph initGraph, string formTitle)
 {
     InitializeComponent();
     this.MdiParent = Program.main;
     graphControl1.LoadLibraries();
     this.Text = formTitle;
     if (initGraph == null) graph1 = new designGraph();
     else graph1 = initGraph;
     graph1.displayGraph(graphControl1, this.globalLabelsText);
 }
Esempio n. 15
0
        /* Parametric application rules receive as input:
        * 1. the location designGraph indicating the nodes&arcs of host that match with L (Lmapping)
        * 2. the entire host graph (host)
        * 3. the location of the nodes in the host that R matches to (Rmapping).
        * 4. the parameters chosen by an agent for instantiating elements of Rmapping or host (parameters). */
        /* This is APPLY for the rule entitled: beginning rule1*/
        public designGraph gearspeedbegrule1(designGraph Lmapping, designGraph host, designGraph Rmapping, double[] parameters)
        {
            double gearspeedrule1 = Program.inputspeed;
            /*taking the speed from the seed*/

            /* setting it into the place on the new gear */
            Rmapping.nodes[1].localVariables[1] = gearspeedrule1;
            Rmapping.nodes[0].localVariables[0] = gearspeedrule1;

            return host;
        }
Esempio n. 16
0
 public node findNewNodeToConnect(designGraph R, designGraph Rmapping)
 {
     /* find R-L node that is to be connected with freeArc as well as old L-R node name*/
     if ((RNodeName != null) && (RNodeName != ""))
     {
         /* take the RNodeName from within the rule and get the proper reference to the new node.
          * If there is no RNodeName, then the embedding rule will set the reference to null. */
         int index = R.nodes.FindIndex(delegate(node b) { return (b.name == RNodeName); });
         return Rmapping.nodes[index];
     }
     else return null;
 }
        /* This is APPLY for the rule entitled: seedBurst2rule3 */
        public designGraph distributeTo2NewRoots(designGraph Lmapping, designGraph host, designGraph Rmapping, double[] parameters)
        {
            for (int i = 1; i <= 2; i++)
            {
                Rmapping.nodes[i].localVariables.Add(Rmapping.nodes[0].localVariables[0] / 2);
                //Rmapping.nodes[i].screenY = 0.0f;
                //Rmapping.nodes[i].screenX = 0.0f;
            }

            Rmapping.nodes[0].localVariables[0] = 0.1;
            return host;
        }
Esempio n. 18
0
 public node findDeletedNode(designGraph L, designGraph Lmapping)
 {
     /* similarly, we can find the LNodeName (if one exists in this particular rule). Setting this
      * up now saves time and space in the below recognition if-then's. */
     if ((LNodeName != null) && (LNodeName != ""))
     {
         int index = L.nodes.FindIndex(delegate(node b) { return(b.name == LNodeName); });
         return(Lmapping.nodes[index]);
     }
     else
     {
         return(null);
     }
 }
Esempio n. 19
0
 /* This is perhaps the whole reason previous states are used.
  * Rules cannot be guaranteed to work in reverse as they work
  * forward, so this simply resets the candidate to how it looked
  * prior to calling the last rule. */
 public void undoLastRule()
 {
     if (prevStates.Count > 0)
     {
         currentState = prevStates[prevStates.Count - 1];
         prevStates.RemoveAt(prevStates.Count - 1);
         recipe.RemoveAt(recipe.Count - 1);
         for (int i = 0; i != performanceParams.Count; i++)
         {
             performanceParams[i] = 0.0;
         }
         age = 0;
     }
 }
Esempio n. 20
0
 public node findNewNodeToConnect(designGraph R, designGraph Rmapping)
 {
     /* find R-L node that is to be connected with freeArc as well as old L-R node name*/
     if ((RNodeName != null) && (RNodeName != ""))
     {
         /* take the RNodeName from within the rule and get the proper reference to the new node.
          * If there is no RNodeName, then the embedding rule will set the reference to null. */
         int index = R.nodes.FindIndex(delegate(node b) { return(b.name == RNodeName); });
         return(Rmapping.nodes[index]);
     }
     else
     {
         return(null);
     }
 }
Esempio n. 21
0
        /* here are parametric rules written as part of the ruleSet.
        * these are compiled at runtime into a .dll indicated in the
        * App.config file. */
        #region Parametric Recognition Rules
        /* Parametric recognition rules receive as input:
* 1. the left hand side of the rule (L)
* 2. the entire host graph (host)
* 3. the location of the nodes in the host that L matches to (locatedNodes).
* 4. the location of the arcs in the host that L matches to (locatedArcs). */
        #endregion


        #region Parametric Application Rules
        /* Parametric application rules receive as input:
         * 1. the location designGraph indicating the nodes&arcs of host that match with L (Lmapping)
         * 2. the entire host graph (host)
         * 3. the location of the nodes in the host that R matches to (Rmapping).
         * 4. the parameters chosen by an agent for instantiating elements of Rmapping or host (parameters). */

        /* This is APPLY for the rule entitled: swirlRule1  */
        public designGraph slopeOfNewEdge(designGraph Lmapping, designGraph host, designGraph Rmapping, double[] parameters)
        {
            edge oldEdge = (edge)Rmapping.arcs[0];
            vertex oldVertex0 = (vertex)Rmapping.nodes[0];
            vertex oldVertex1 = (vertex)Rmapping.nodes[1];
            double newAngle = System.Math.Atan2((oldVertex1.y - oldVertex0.y), (oldVertex1.x - oldVertex0.x)) - 0.4;
            double newLength = 1.05 * oldEdge.length;
            vertex newVertex = (vertex)Rmapping.nodes[2];
            newVertex.x = oldVertex1.x + newLength * System.Math.Cos(newAngle);
            newVertex.screenX = (float)newVertex.x;
            newVertex.y = oldVertex1.y + newLength * System.Math.Sin(newAngle);
            newVertex.screenY = (float)newVertex.y;

            return host;
        }
Esempio n. 22
0
        /// <summary>
        /// Creates an empty location graph used in recognition.
        /// </summary>
        /// <param name="numNodes">The num nodes.</param>
        /// <param name="numArcs">The num arcs.</param>
        /// <param name="numHyperArcs">The num hyper arcs.</param>
        /// <returns></returns>
        public static designGraph CreateEmptyLocationGraph(int numNodes, int numArcs, int numHyperArcs = 0)
        {
            var emptyGraph = new designGraph();

            for (var i = 0; i != numNodes; i++)
            {
                emptyGraph.nodes.Add(null);
            }
            for (var i = 0; i != numArcs; i++)
            {
                emptyGraph.arcs.Add(null);
            }
            for (var i = 0; i != numHyperArcs; i++)
            {
                emptyGraph.hyperarcs.Add(null);
            }
            return(emptyGraph);
        }
Esempio n. 23
0
        public void apply(designGraph Lmapping, designGraph host, double[] parameters)
        {
            /* Update the global labels.*/
            foreach (string a in L.globalLabels)
                if (!R.globalLabels.Contains(a))
                    host.globalLabels.Remove(a);          /* removing the labels in L but not in R...*/
            foreach (string a in R.globalLabels)
                if (!L.globalLabels.Contains(a))
                    host.globalLabels.Add(a.ToString());          /*...and adding the label in R but not in L.*/
            foreach (double a in L.globalVariables)         /* do the same now, for the variables. */
                if (!R.globalVariables.Contains(a))
                    host.globalVariables.Remove(a);          /* removing the labels in L but not in R...*/
            foreach (double a in R.globalVariables)
                if (!L.globalVariables.Contains(a))
                    host.globalVariables.Add(a);          /*...and adding the label in R but not in L.*/

            /* First set up the Rmapping, which is a list of nodes within the host
             * that corresponds in length and position to the nodes in R, just as
             * Lmapping contains lists of nodes and arcs in the order they are
             * referred to in L. */
            designGraph Rmapping = new designGraph();
            foreach (node a in R.nodes)     /* we do not know what these will point to yet, so just */
                Rmapping.nodes.Add(null);   /* make it of proper length at this point. */
            foreach (arc a in R.arcs)       /* DEBUG HINT: you should check Rmapping at the end of */
                Rmapping.arcs.Add(null);     /* the function - it should contain no nulls. */

            removeLdiffKfromHost(Lmapping, host);
            addRdiffKtoD(Lmapping, host, Rmapping);
            /* these two lines correspond to the two "pushouts" of the double pushout algorithm.
             *     L <--- K ---> R     this is from freeArc embedding (aka edNCE)
             *     |      |      |        |      this is from the parametric update
             *     |      |      |        |       |
             *   host <-- D ---> H1 ---> H2 ---> H3
             * The first step is to create D by removing the part of L not found in K (the commonality).
             * Second, we add the elements of R not found in K to D to create the updated host, H. Note,
             * that in order to do this, we must know what subgraph of the host we are manipulating - this
             * is the location mapping found by the recognize function. */

            freeArcEmbedding(Lmapping, host, Rmapping);
            /* however, there may still be a need to embed the graph with other arcs left dangling,
             * as in the "edge directed Node Controlled Embedding approach", which considers the neighbor-
             * hood of nodes and arcs of the recognized Lmapping. */
            updateParameters(Lmapping, host, Rmapping, parameters);
        }
Esempio n. 24
0
 public void showProperties(Netron.GraphLib.UI.GraphControl GC, designGraph graph1, object[] props)
 {
     graphControl = GC;
     graph = graph1;
     rule = null;
     try
     {
         graph.updateFromGraphControl(graphControl);
         if (graph.Bag == null) graph.initPropertiesBag();
         this.graphRuleProps.SelectedObject = graph.Bag;
         this.graphRulePropsTab.Text = "Graph Properties";
     }
     catch (Exception exc)
     {
         MessageBox.Show("The properties of the graph has thrown an exception and cannot be displayed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         SearchIO.output(exc.Message, 2);
     }
     showDisplayProperties(graphControl, (Netron.GraphLib.PropertyBag)props[0]);
     showNodeArcProperties((Netron.GraphLib.PropertyBag)props[0], graph);
 }
Esempio n. 25
0
 public static void saveGraphToXml(string filename, designGraph graph1)
 {
     graph1.checkForRepeatNames();
     StreamWriter graphWriter = null;
     try
     {
         graphWriter = new StreamWriter(filename);
         XmlSerializer graphSerializer = new XmlSerializer(typeof(designGraph));
         graphSerializer.Serialize(graphWriter, graph1);
     }
     catch (Exception ioe)
     {
         MessageBox.Show(ioe.ToString(), "XML Serialization Error", MessageBoxButtons.OK,
             MessageBoxIcon.Information);
     }
     finally
     {
         if (graphWriter != null) graphWriter.Close();
     }
 }
        /// <summary>
        /// This is the recognize function called within the RCA generation. It is
        /// fairly straightforward method that basically invokes the more complex
        /// recognize function for each rule within it, and returns a list of
        /// options.
        /// </summary>
        /// <param name="host">The host.</param>
        /// <param name="InParallel">if set to <c>true</c> [in parallel].</param>
        /// <param name="RelaxationTemplate">The relaxation template.</param>
        /// <returns></returns>
        public List <option> recognize(designGraph host, Boolean InParallel = true, Relaxation RelaxationTemplate = null)
        {
            var options = new List <option>();

            if (rules.Count == 0)
            {
                return(options);
            }
            if (choiceMethod == choiceMethods.Automatic)
            {
                for (var i = 0; i != rules.Count; i++)
                {
                    var ruleOpts = rules[i].recognize(host, InParallel, (generationAfterNoRules == nextGenerationSteps.Stop) ? RelaxationTemplate : null);
                    if (ruleOpts.Count > 0)
                    {
                        var r0 = ruleOpts[0];
                        r0.assignRuleInfo(i + 1, RuleSetIndex);
                        return(new List <option> {
                            r0
                        });
                    }
                }
            }
            else if (InParallel)/* new parallel rule check */
            {
                options = rules.SelectMany((rule, ruleIndex) =>
                                           rule.recognize(host, true, (generationAfterNoRules == nextGenerationSteps.Stop) ? RelaxationTemplate : null)
                                           .Select(o => o.assignRuleInfo(ruleIndex + 1, RuleSetIndex))).AsParallel().ToList();
            }
            else /* do in series */
            {
                options = rules.SelectMany((rule, ruleIndex) =>
                                           rule.recognize(host, false, (generationAfterNoRules == nextGenerationSteps.Stop) ? RelaxationTemplate : null)
                                           .Select(o => o.assignRuleInfo(ruleIndex + 1, RuleSetIndex))).ToList();
            }
            for (var i = 0; i < options.Count; i++)
            {
                options[i].optionNumber = i;
            }
            return(options);
        }
Esempio n. 27
0
        /// <summary>
        ///   Creates a complete graph where every node is connected to every
        ///   other node by an arc.
        /// </summary>
        /// <param name="numNodes">The number of nodes.</param>
        /// <returns></returns>
        public static designGraph CreateCompleteGraph(int numNodes)
        {
            var numArcs       = numNodes * (numNodes - 1) / 2;
            var completeGraph = new designGraph
            {
                name = "CompleteGraph_with_" + numNodes + "_nodes_and_" + numArcs + "_arcs"
            };

            for (var i = 0; i != numNodes; i++)
            {
                completeGraph.addNode();
            }
            for (var i = 0; i != numNodes; i++)
            {
                for (var j = i + 1; j != numNodes; j++)
                {
                    completeGraph.addArc(completeGraph.nodes[i], completeGraph.nodes[j]);
                }
            }
            return(completeGraph);
        }
Esempio n. 28
0
        /* This is APPLY for the rule entitled: aftersgos */
        public designGraph gearspeedas(designGraph Lmapping, designGraph host, designGraph Rmapping, double[] parameters)
        {
            double gearmaas = Lmapping.nodes[0].localVariables[0];
            double gearspeedas = Lmapping.nodes[0].localVariables[1];
            double radius1as = Lmapping.nodes[0].localVariables[3];
            double teeth1as = Lmapping.nodes[0].localVariables[2];
            /* obtaining values for old properties */

            Rmapping.nodes[0].localVariables[1] = gearspeedas;
            Rmapping.nodes[0].localVariables[2] = teeth1as;
            Rmapping.nodes[0].localVariables[3] = radius1as;
            Rmapping.nodes[0].localVariables[0] = gearmaas;
            /* setting old gear properties*/

            double teeth2as = Rmapping.nodes[1].localVariables[2];
            double radius2as = Rmapping.nodes[1].localVariables[3];
            /*obtaining new gear properties from right*/

            Rmapping.nodes[1].localVariables[0] = (-(teeth1as / teeth2as)) * gearmaas;
            Rmapping.nodes[1].localVariables[1] = -((gearspeedas * radius1as) / radius2as);

            return host;
        }
Esempio n. 29
0
 /* This is the recognize function called within the RCA generation. It is 
  * fairly straightforward method that basically invokes the more complex
  * recognize function for each rule within it, and returns a list of
  * options. */
 public List<option> recognize(designGraph host)
 {
     List<designGraph> locations = new List<designGraph>();
     List<option> options = new List<option>();
     if (rules.Count == 0) return options;
     for (int i = 0; i != rules.Count; i++)
     {
         locations = rules[i].recognize(host);
         if (locations.Count > 0)
             foreach (designGraph a in locations)
             {
                 options.Add(new option());
                 options[options.Count - 1].ruleSetIndex = this.ruleSetIndex;
                 options[options.Count - 1].ruleNumber = i + 1;
                 options[options.Count - 1].rule = rules[i];
                 options[options.Count - 1].location = a;
                 if (this.choiceMethod == choiceMethods.Automatic) return options;
                 /* this is merely for efficiency - once we get one valid option for
                  * an Automatic ruleset we can exit and invoke that option. */
             }
     }
     return options;
 }
Esempio n. 30
0
        public void showProperties(Netron.GraphLib.UI.GraphControl GC, grammarRule rule1, object[] props)
        {
            graphControl = GC;
            rule = rule1;

            if (graphControl.Name == "graphControlLHS") graph = rule.L;
            else graph = rule.R;

            rule.updateFromGraphControl(graphControl);
            try
            {
                this.graphRulePropsTab.Text = "Rule Properties";
                if (rule.Bag == null) rule.initPropertiesBag();
                this.graphRuleProps.SelectedObject = rule.Bag;
            }
            catch (Exception exc)
            {
                MessageBox.Show("The properties of the rule has thrown an exception and cannot be displayed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                SearchIO.output(exc.Message, 2);
            }
            showDisplayProperties(graphControl, (Netron.GraphLib.PropertyBag)props[0]);
            showRuleNodeArcProperties((Netron.GraphLib.PropertyBag)props[0], graph);
        }
Esempio n. 31
0
        /* if allowArcDuplication is true then for each rule that matches with the arc the arc will be 
         * duplicated. */

        public static Boolean arcIsFree(arc a, designGraph host, out sbyte freeEndIdentifier, node neighborNode)
        {
            if (a.From != null && a.To != null &&
                !host.nodes.Contains(a.From) && !host.nodes.Contains(a.To))
            {
                freeEndIdentifier = 0;
                /* if the nodes on either end of the freeArc are pointing to previous nodes 
                 * that were deleted in the first pushout then neighborNode is null (and as
                 * a result any rules using the neighborNodeLabel will not apply) and the 
                 * freeEndIdentifier is zero. */
                neighborNode = null;
                return true;
            }
            else if (a.From != null && !host.nodes.Contains(a.From))
            {
                freeEndIdentifier = -1;
                /* freeEndIdentifier set to -1 means that the From end of the arc must be the free end.*/
                neighborNode = a.To;
                return true;
            }
            else if (a.To != null && !host.nodes.Contains(a.To))
            {
                freeEndIdentifier = +1;
                /* freeEndIdentifier set to +1 means that the To end of the arc must be the free end.*/
                neighborNode = a.From;
                return true;
            }
            else
            {
                /* else, the arc is not a free arc after all and we simply break out 
                 * of this loop and try the next arc. */
                freeEndIdentifier = 0;
                neighborNode = null;
                return false;
            }

        }
Esempio n. 32
0
        public static void saveGraphToXml(string filename, designGraph graph1)
        {
            graph1.checkForRepeatNames();
            StreamWriter graphWriter = null;

            try
            {
                graphWriter = new StreamWriter(filename);
                XmlSerializer graphSerializer = new XmlSerializer(typeof(designGraph));
                graphSerializer.Serialize(graphWriter, graph1);
            }
            catch (Exception ioe)
            {
                MessageBox.Show(ioe.ToString(), "XML Serialization Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
            finally
            {
                if (graphWriter != null)
                {
                    graphWriter.Close();
                }
            }
        }
 public randomChooseWithUndo(designGraph _seed, ruleSet[] _rulesets, int[] _maxNumOfCalls)
     : base(_seed, _rulesets, _maxNumOfCalls, false) { }
 public randomChooseWithUndo(designGraph _seed, ruleSet[] _rulesets, int _maxRulesToApply)
     : base(_seed, _rulesets, _maxRulesToApply, false) { }
 public randomChooseWithUndo(designGraph _seed, ruleSet[] _rulesets, Boolean _display)
     : base(_seed, _rulesets, -1, _display) { }
 public randomChooseWithUndo(designGraph _seed, ruleSet[] _rulesets)
     : base(_seed, _rulesets, -1, false) { }
        /* a constructor like these are needed to invoke the main constructor in RecognizeChooseApply.cs */
        public randomChooseWithUndo(designGraph _seed, ruleSet[] _rulesets, int _maxRulesToApply,
            Boolean recompileRules, string execDir, string compiledparamRules)
            : base(_seed, _rulesets, _maxRulesToApply, false, recompileRules, execDir,
compiledparamRules) { }
 public randomChooseWithUndo(designGraph _seed, ruleSet[] _rulesets, int[] _maxNumOfCalls, Boolean _display,
      Boolean recompileRules, string execDir, string compiledparamRules)
     : base(_seed, _rulesets, _maxNumOfCalls, _display, recompileRules, execDir, compiledparamRules) { }
Esempio n. 39
0
 /// <summary>
 ///   Applies the option to the specified host. It is essentially
 ///   a shorthand instead of calling
 ///   option.rule.apply(option.location, host, parameters); we call
 ///   option.apply(host, parameters).
 /// </summary>
 /// <param name = "host">The host.</param>
 /// <param name = "Parameters">The parameters.</param>
 public void apply(designGraph host, double[] Parameters)
 {
     rule.apply(host, this, Parameters);
 }
Esempio n. 40
0
        /// <summary>
        ///   Copies the specified make deep copy.
        /// </summary>
        /// <param name = "MakeDeepCopy">if set to <c>true</c> [make deep copy].</param>
        /// <returns></returns>
        public designGraph copy(Boolean MakeDeepCopy = true)
        {
            /* at times we want to copy a graph and not refer to the same objects. This happens mainly
             * (rather initially what inspired this function) when the seed graph is copied into a candidate.*/
            var copyOfGraph = new designGraph {
                name = name
            };

            foreach (var label in globalLabels)
            {
                copyOfGraph.globalLabels.Add(label);
            }
            foreach (var v in globalVariables)
            {
                copyOfGraph.globalVariables.Add(v);
            }
            foreach (var origNode in nodes)
            {
                copyOfGraph.addNode(MakeDeepCopy ? origNode.copy() : origNode);
            }
            foreach (var origArc in arcs)
            {
                if (MakeDeepCopy)
                {
                    var  copyOfArc = origArc.copy();
                    var  toIndex   = nodes.FindIndex(a => (a == origArc.To));
                    var  fromIndex = nodes.FindIndex(b => (b == origArc.From));
                    node fromNode  = null;
                    if (fromIndex > -1)
                    {
                        fromNode = copyOfGraph.nodes[fromIndex];
                    }
                    node toNode = null;
                    if (toIndex > -1)
                    {
                        toNode = copyOfGraph.nodes[toIndex];
                    }
                    copyOfGraph.addArc(copyOfArc, fromNode, toNode);
                }
                else
                {
                    copyOfGraph.arcs.Add(origArc);
                }
            }
            foreach (var origHyperArc in hyperarcs)
            {
                if (MakeDeepCopy)
                {
                    var copyOfHyperArc = origHyperArc.copy();
                    var attachedNodes  = new List <node>();
                    foreach (var n in origHyperArc.nodes)
                    {
                        var index = nodes.FindIndex(a => (a == n));
                        attachedNodes.Add(copyOfGraph.nodes[index]);
                    }
                    copyOfGraph.addHyperArc(copyOfHyperArc, attachedNodes);
                }
                else
                {
                    copyOfGraph.hyperarcs.Add(origHyperArc);
                }
            }
            return(copyOfGraph);
        }
Esempio n. 41
0
 public static void addAndShowGraphDisplay(designGraph graph, string title)
 {
     object[] paramValues = { graph, title };
     SafeInvokeHelper.Invoke(main, "addAndShowGraphDisplay", paramValues);
 }
Esempio n. 42
0
 public void apply(designGraph host, double[] parameters)
 {
     rule.apply(location, host, parameters);
 }
 public randomChooseWithUndo(designGraph _seed, ruleSet[] _rulesets, int _maxRulesToApply, Boolean _display)
     : base(_seed, _rulesets, _maxRulesToApply, _display) { }
Esempio n. 44
0
        /* This is APPLY for the rule entitled: terminal rule */
        public designGraph gearspeedterm(designGraph Lmapping, designGraph host, designGraph Rmapping, double[] parameters)
        {
            double gearmaterm = Lmapping.nodes[0].localVariables[0];
            double gearspeedterm = Lmapping.nodes[0].localVariables[1];
            double radius1term = Lmapping.nodes[0].localVariables[3];
            double teeth1term = Lmapping.nodes[0].localVariables[2];

            double gearma2term = Lmapping.nodes[1].localVariables[0];
            double gearspeed2term = Lmapping.nodes[1].localVariables[1];
            double radius2term = Lmapping.nodes[1].localVariables[3];
            double teeth2term = Lmapping.nodes[1].localVariables[2];
            /* obtaining values for old properties */

            Rmapping.nodes[1].localVariables[1] = gearspeedterm;
            Rmapping.nodes[1].localVariables[0] = gearmaterm;
            /* setting shaft on right properties*/

            Rmapping.nodes[0].localVariables[1] = gearspeedterm;
            Rmapping.nodes[0].localVariables[2] = teeth1term;
            Rmapping.nodes[0].localVariables[3] = radius1term;
            Rmapping.nodes[0].localVariables[0] = gearmaterm;

            Rmapping.nodes[4].localVariables[1] = gearspeed2term;
            Rmapping.nodes[4].localVariables[2] = teeth2term;
            Rmapping.nodes[4].localVariables[3] = radius2term;
            Rmapping.nodes[4].localVariables[0] = gearma2term;
            /* setting old gear properties*/

            return host;
        }
Esempio n. 45
0
        /* This is APPLY for the rules entitled: smallergearonshaft*/
        public designGraph gearspeedsgs(designGraph Lmapping, designGraph host, designGraph Rmapping, double[] parameters)
        {
            double gearmasgs = Lmapping.nodes[0].localVariables[0];
            double gearspeed1 = Lmapping.nodes[0].localVariables[1];
            double radius1sgs = Lmapping.nodes[0].localVariables[3];
            double teeth1sgs = Lmapping.nodes[0].localVariables[2];
            /* obtaining values for old gear 1 properties */

            double gearma2sgs = Lmapping.nodes[1].localVariables[0];
            double gearspeed2 = Lmapping.nodes[1].localVariables[1];
            double radius2sgs = Lmapping.nodes[1].localVariables[3];
            double teeth2sgs = Lmapping.nodes[1].localVariables[2];
            /* obtaining values for old gear 2 properties */

            Rmapping.nodes[1].localVariables[0] = gearspeed1;
            /* setting shaft on right gear 2 properties*/

            Rmapping.nodes[0].localVariables[1] = gearspeed1;
            Rmapping.nodes[0].localVariables[2] = teeth1sgs;
            Rmapping.nodes[0].localVariables[3] = radius1sgs;
            Rmapping.nodes[0].localVariables[0] = gearmasgs;
            /* setting old gear 1 properties*/

            Rmapping.nodes[5].localVariables[1] = gearspeed2;
            Rmapping.nodes[5].localVariables[2] = teeth2sgs;
            Rmapping.nodes[5].localVariables[3] = radius2sgs;
            Rmapping.nodes[5].localVariables[0] = gearma2sgs;
            /* setting old gear 2 properties*/

            double teeth3sgs = Rmapping.nodes[4].localVariables[2];
            double radius3sgs = Rmapping.nodes[4].localVariables[3];
            /*obtaining new gear properties from right*/

            Rmapping.nodes[4].localVariables[0] = (-(teeth1sgs/teeth3sgs))*gearmasgs;
            Rmapping.nodes[4].localVariables[1] = gearspeed1;
            /* setting new properties with calculations*/

            return host;
        }
Esempio n. 46
0
        /* if allowArcDuplication is true then for each rule that matches with the arc the arc will be
         * duplicated. */

        #endregion

        #region Methods

        internal static Boolean hyperArcIsFree(hyperarc dangleHyperArc, designGraph host, out List <node> neighborNodes)
        {
            neighborNodes = dangleHyperArc.nodes.Where(n => !host.nodes.Contains(n)).ToList();
            return(neighborNodes.Count > 0);
        }
Esempio n. 47
0
        /* This is APPLY for the rules entitled: singleidler*/
        public designGraph gearspeedidler(designGraph Lmapping, designGraph host, designGraph Rmapping, double[] parameters)
        {
            double gearmaidle = Lmapping.nodes[0].localVariables[0];
            double gearspeedidle = Lmapping.nodes[0].localVariables[1];
            double radius1idle = Lmapping.nodes[0].localVariables[3];
            double teeth1idle = Lmapping.nodes[0].localVariables[2];
            /* obtaining values for old properties */

            /*Shaft speed is already set to 0*/

            Rmapping.nodes[0].localVariables[1] = gearspeedidle;
            Rmapping.nodes[0].localVariables[2] = teeth1idle;
            Rmapping.nodes[0].localVariables[3] = radius1idle;
            Rmapping.nodes[0].localVariables[0] = gearmaidle;
            /* setting old gear properties*/

            double teeth2idle = Rmapping.nodes[3].localVariables[2];
            double radius2idle = Rmapping.nodes[3].localVariables[3];
            /*obtaining new gear properties from right*/

            Rmapping.nodes[3].localVariables[0] = (-(teeth1idle/teeth2idle)) * gearmaidle;
            Rmapping.nodes[3].localVariables[1] = -((gearspeedidle * radius1idle)/radius2idle);
            /* setting new properties with calculations*/

            return host;
        }
 public randomChooseWithUndo(designGraph _seed, ruleSet[] _rulesets, int[] _maxNumOfCalls, Boolean _display)
     : base(_seed, _rulesets, _maxNumOfCalls, _display) { }
Esempio n. 49
0
 public void apply(designGraph host, double[] parameters)
 {
     rule.apply(location, host, parameters);
 }