public IList<AbstractComponentFunctorParameter> list(int id_abstract)
    {
        IList<AbstractComponentFunctorParameter> list = null;
        
        if (cache_c_pars.TryGetValue(id_abstract, out list)) return list;

        list = new List<AbstractComponentFunctorParameter>();

        cache_c_pars.Add(id_abstract, list);

	   IDbConnection dbcon = Connector.DBcon;
       IDbCommand dbcmd = dbcon.CreateCommand();
       string sql =
           "SELECT id_abstract, id_parameter, bounds_of, variance " +
           "FROM abstractcomponentfunctorparameter " +
           "WHERE id_abstract="+id_abstract;
       dbcmd.CommandText = sql;
       IDataReader reader = dbcmd.ExecuteReader();
       while(reader.Read()) {
       		AbstractComponentFunctorParameter acfp = new AbstractComponentFunctorParameter();
			acfp.Bounds_of = (int)reader["bounds_of"];
			acfp.Id_abstract = (int)reader["id_abstract"];
			acfp.Id_parameter = (string)reader["id_parameter"] ;
			acfp.Variance =  Constants.varianceValueInv[(string)reader["variance"]];
            list.Add(acfp);
       }//while
       // clean up
       reader.Close();
       reader = null;
       dbcmd.Dispose();
       dbcmd = null;
       return list;
       
	}//lis
        public void insert(AbstractComponentFunctorParameter ac)
        {
            String sql =
                "INSERT INTO abstractcomponentfunctorparameter (id_parameter, id_abstract, bounds_of, variance)" +
                " VALUES ('" + ac.Id_parameter + "'," + ac.Id_abstract + "," + ac.Bounds_of + ",'" + ac.Variance + "')";

     		Console.WriteLine("AbstractComponentFunctorParameter.cs: TRY INSERT: " + sql);

            Connector.performSQLUpdate(sql);

        }
    internal AbstractComponentFunctorParameter retrieve(int id_abstract, string id_parameter)
    {
        AbstractComponentFunctorParameter acfp = null;

        int key = makeKey(id_abstract, id_parameter);
        if (cache_c_pars_2.TryGetValue(key, out acfp))
        {
                return acfp;
        }
        
        IDbConnection dbcon = Connector.DBcon;
        IDbCommand dbcmd = dbcon.CreateCommand();
        string sql =
            "SELECT id_abstract, id_parameter, bounds_of, variance " +
            "FROM abstractcomponentfunctorparameter " +
            "WHERE id_abstract=" + id_abstract + " AND id_parameter like '" + id_parameter + "'";
        dbcmd.CommandText = sql;
        IDataReader reader = dbcmd.ExecuteReader();
        if (reader.Read())
        {
            acfp = new AbstractComponentFunctorParameter();
            acfp.Bounds_of = (int)reader["bounds_of"];
            acfp.Id_abstract = (int)reader["id_abstract"];
            acfp.Id_parameter = (string)reader["id_parameter"];
			acfp.Variance =  Constants.varianceValueInv[(string)reader["variance"]];
            cache_c_pars_2.Add(key, acfp);
        }//if

        // clean up
        reader.Close();
        reader = null;
        dbcmd.Dispose();
        dbcmd = null;
			
	   if (acfp==null) 
	   {
	  	  Console.WriteLine("AbstractComponentFunctorParameterDAO.cs: PARAMETER NOT FOUND "+ id_abstract + "," + id_parameter);
	   }
			
        return acfp;
    }
Exemplo n.º 4
0
        public static TreeNode generate(IDictionary <string, int> actualParametersTop, AbstractComponentFunctorApplication acfaRef)
        {
            //foreach (KeyValuePair<string,int> parTop in actualParametersTop)
            //	Console.WriteLine ("actualParametersTop[" + parTop.Key + "] = " + parTop.Value);

            //foreach (KeyValuePair<string,int> parTop in acfaRef.ParametersList)
            //	Console.WriteLine ("acfaRef.ParametersList[" + parTop.Key + "] = " + parTop.Value);

            IDictionary <TreeNode, int> level_log = new Dictionary <TreeNode, int> ();

            //Console.WriteLine("begin generate " + acfaRef.Id_functor_app);
            mmm = new Dictionary <String, String>();

            IDictionary <int, TreeNode> memory = new Dictionary <int, TreeNode>();

            IList <AbstractComponentFunctorApplication> lll = new List <AbstractComponentFunctorApplication>();

            lll.Add(acfaRef);

            TreeNode  root  = new TreeNode(lll, null);
            ArrayList queue = new ArrayList();

            queue.Add(root);

            level_log.Add(root, 0);

            while (queue.Count != 0)
            {
                TreeNode nodeRef = (TreeNode)queue[0];

                int level = level_log[nodeRef];
                //Console.WriteLine ("ENTERING LEVEL " + level);

                int id_abstract           = nodeRef.Functor_app.Id_abstract;
                int id_functor_app_actual = nodeRef.Functor_app.Id_functor_app;
                int id_abstract_top       = nodeRef.Functor_app_top.Id_abstract;

                //Console.WriteLine("Dequeue LOOP " + id_functor_app_actual);

                queue.RemoveAt(0);

                IList <SupplyParameter> parameterList = br.ufc.pargo.hpe.backend.DGAC.BackEnd.spdao.list2(id_functor_app_actual);
                foreach (SupplyParameter sp in parameterList)
                {
                    bool flag_par = false;
                    //	Console.WriteLine("generate LOOP " + sp.Id_parameter + "," + sp.Id_functor_app + "IN LEVEL " + level);
                    bool freeVariable = false;

                    string parameter_id = sp.Id_parameter;

                    AbstractComponentFunctorApplication acfaTop = null;
                    if (id_abstract_top != id_abstract)
                    {
                        AbstractComponentFunctorParameter acfpTop = br.ufc.pargo.hpe.backend.DGAC.BackEnd.acfpdao.retrieve(id_abstract_top, parameter_id);
                        acfaTop = acfpTop == null ? null : br.ufc.pargo.hpe.backend.DGAC.BackEnd.acfadao.retrieve(acfpTop.Bounds_of);
                        if (acfaTop == null)
                        {
                            AbstractComponentFunctorParameter acfp = br.ufc.pargo.hpe.backend.DGAC.BackEnd.acfpdao.retrieve(id_abstract, parameter_id);
                            acfaTop = acfp == null ? null : br.ufc.pargo.hpe.backend.DGAC.BackEnd.acfadao.retrieve(acfp.Bounds_of);
                        }
                    }
                    else
                    {
                        AbstractComponentFunctorParameter acfp = br.ufc.pargo.hpe.backend.DGAC.BackEnd.acfpdao.retrieve(id_abstract, parameter_id);
                        acfaTop = acfp == null ? null : br.ufc.pargo.hpe.backend.DGAC.BackEnd.acfadao.retrieve(acfp.Bounds_of);
                    }

                    //Console.WriteLine("acfaTop is null ? " + (acfaTop==null));

                    AbstractComponentFunctorApplication acfaActual = null;
                    if (sp is SupplyParameterComponent)
                    {
                        SupplyParameterComponent spc = (SupplyParameterComponent)sp;
                        //	Console.WriteLine ("acfaActual 1 ??? " + spc.Id_functor_app_actual);
                        acfaActual = br.ufc.pargo.hpe.backend.DGAC.BackEnd.acfadao.retrieve(spc.Id_functor_app_actual);
                        if (acfaActual == null)
                        {
                            throw new FreeVariableException();
                        }
                        //flag_par = true;
                    }
                    else if (sp is SupplyParameterParameter)
                    {
                        SupplyParameterParameter spp = (SupplyParameterParameter)sp;
                        int Id_functor_app_actual    = 0;

                        //	Console.WriteLine ("****** parameter_id#??? =" + parameter_id + "#" + sp.Id_functor_app);
                        if (!(flag_par = acfaRef.ParametersList.TryGetValue(parameter_id + "#" + sp.Id_functor_app, out Id_functor_app_actual)))
                        {
                            acfaRef.ParametersList.TryGetValue(parameter_id, out Id_functor_app_actual);
                        }

                        //	Console.WriteLine (" acfaRef.ParametersList.Count = " + acfaRef.ParametersList.Count);
                        //	foreach (KeyValuePair<string,int> p in acfaRef.ParametersList)
                        //		Console.WriteLine("acfaRef.ParametersList -- " + p.Key + " -> " + p.Value);

                        if (Id_functor_app_actual <= 0) // LOOK AT THE TOP PARAMETERS
                        {
                            bool found = actualParametersTop.TryGetValue(spp.Id_argument, out Id_functor_app_actual);
                            //	    Console.WriteLine (" actualParametersTop.Count = " + actualParametersTop.Count);
                            //	    foreach (KeyValuePair<string,int> p in actualParametersTop)
                            //		     Console.WriteLine("actualParametersTop -- " + p.Key + " -> " + p.Value);
                            if (!found)
                            {
                                string key = spp.Id_argument + "#" + sp.Id_functor_app;
                                //		Console.WriteLine ("key ??? " + key);
                                acfaRef.ParametersList.TryGetValue(key, out Id_functor_app_actual);
                            }

                            //	Console.WriteLine ("spp.Id_parameter_actual ??? " + spp.Id_argument);
                            //	Console.WriteLine ("found ??? " + found);
                        }
                        //	Console.WriteLine ("acfaRef ??? " + acfaRef.Id_functor_app);
                        //	Console.WriteLine ("parameter_id ??? " + parameter_id);
                        //	Console.WriteLine ("acfaActual 2 ??? " + Id_functor_app_actual);
                        if (Id_functor_app_actual <= 0)
                        {
                            // FREE VARIABLE !!! USE THE BOUND !!!
                            //AbstractComponentFunctorApplication acfaParF = br.ufc.pargo.hpe.backend.DGAC.BackEnd.acfadao.retrieve(spp.Id_functor_app);
                            //AbstractComponentFunctorParameter parF = br.ufc.pargo.hpe.backend.DGAC.BackEnd.acfpdao.retrieve(acfaParF.Id_abstract,parameter_id);
                            //Id_functor_app_actual = parF.Bounds_of;
                            //Console.WriteLine ("FREE VARIABLE !!! BOUND=" + Id_functor_app_actual);
                            freeVariable = true;
                        }
                        acfaActual = br.ufc.pargo.hpe.backend.DGAC.BackEnd.acfadao.retrieve(Id_functor_app_actual);
                    }

                    //	Console.WriteLine ("acfaActual ??? " + acfaActual.Id_functor_app);

                    if (!freeVariable)
                    {
                        // LOOK FOR ACTUAL PARAMETER IDs for THE NEXT ITERATIONS !!!
                        //	Console.WriteLine ("acfaTop.Id_functor_app = " + acfaTop.Id_functor_app);
                        IList <SupplyParameter> sss = br.ufc.pargo.hpe.backend.DGAC.BackEnd.spdao.list(acfaTop.Id_functor_app);
                        foreach (SupplyParameter sssx in sss)
                        {
                            if (sssx is SupplyParameterComponent)
                            {
                                SupplyParameterComponent ssxc = (SupplyParameterComponent)sssx;
                                if (!mmm.ContainsKey(acfaActual.Id_functor_app + "." + ssxc.Id_parameter))
                                {
                                    mmm.Add(acfaActual.Id_functor_app + "." + ssxc.Id_parameter, ssxc.Id_parameter);
                                }
                            }
                            else if (sssx is SupplyParameterParameter)
                            {
                                SupplyParameterParameter ssxp = (SupplyParameterParameter)sssx;
                                if (!mmm.ContainsKey(acfaActual.Id_functor_app + "." + ssxp.Id_parameter))
                                {
                                    mmm.Add(acfaActual.Id_functor_app + "." + ssxp.Id_parameter, ssxp.Id_argument);
                                }
                            }
                        }

                        int    memory_key = acfaActual.Id_functor_app;
                        string parameter_id_2;
                        mmm.TryGetValue(id_functor_app_actual + "." + parameter_id, out parameter_id_2);
                        if (parameter_id_2 == null)
                        {
                            parameter_id_2 = parameter_id;
                        }
                        else
                        {
                            acfaRef.ParametersList.TryGetValue(parameter_id_2, out memory_key);
                        }

                        TreeNode node       = null;
                        bool     node_found = memory.TryGetValue(memory_key, out node);

                        //		foreach (KeyValuePair<string, string> ppp in mmm)
                        //			Console.WriteLine ("mmm[" + ppp.Key + "]=" + ppp.Value);
                        //		foreach (KeyValuePair<int, TreeNode> pair in memory)
                        //			Console.WriteLine ("memory: key=" + pair.Key + ", value=" + pair.Value.Functor_app.Id_functor_app);

                        if (!node_found)
                        {
                            IList <AbstractComponentFunctorApplication> generalizeSteps = buildGeneralizationSteps(acfaActual, acfaTop);

                            //			foreach (AbstractComponentFunctorApplication yyy in generalizeSteps)
                            //				Console.WriteLine("generate - " + yyy.Id_functor_app);

                            node = new TreeNode(generalizeSteps, nodeRef);
                            level_log.Add(node, level + 1);
                            node.addParameterIdSyn(parameter_id_2);
                            node.Parameter_id = parameter_id_2;
                            queue.Add(node);
                            //			Console.WriteLine("BEGIN " + parameter_id + "," + parameter_id_2 + "," + flag_par + " *** "  + node.Functor_app.Id_functor_app);
                            if (level == 0 || flag_par)
                            {
                                memory.Add(node.Functor_app.Id_functor_app /*parameter_id_2 + (flag_par ? sp.Id_functor_app.ToString () : "")*/, node);
                            }
                            //			else
                            //				Console.WriteLine ("LEVEL " + level);
                            //			Console.WriteLine("END" + parameter_id + "," + parameter_id_2);
                        }
                        else
                        {
                            //			Console.WriteLine ("parameter_id_2 = " + parameter_id_2 + (flag_par ? sp.Id_functor_app.ToString() : ""));
                            node.addParameterIdSyn(parameter_id_2);
                        }

                        nodeRef.addChild(node);
                    }
                    else
                    {
                    }
                }
            }

            //	Console.WriteLine("end generate " + root.Parameter_id + "," +  root.Functor_app.Id_functor_app);
            return(root);
        }
Exemplo n.º 5
0
        private void collectParameters(IDictionary <string, AbstractComponentFunctorApplication> pars,
                                       AbstractComponentFunctorApplication acfa,
                                       out IDictionary <string, AbstractComponentFunctorApplication> parsSlice)
        {
            IList <SupplyParameter> spList = br.ufc.pargo.hpe.backend.DGAC.BackEnd.spdao.list(acfa.Id_functor_app);

            parsSlice = new Dictionary <string, AbstractComponentFunctorApplication>();

            foreach (SupplyParameter sp in spList)
            {
                AbstractComponentFunctorApplication acfaPar = null;
                if (sp is SupplyParameterComponent)
                {
                    SupplyParameterComponent sp_ = (SupplyParameterComponent)sp;
                    acfaPar = br.ufc.pargo.hpe.backend.DGAC.BackEnd.acfadao.retrieve(sp_.Id_functor_app_actual);
                    parsSlice.Add(sp_.Id_parameter, acfaPar);
                    Console.WriteLine("collectParameter -TRACE 1 " + sp_.Id_parameter + ":" + acfaPar.Id_abstract);
                }
                else if (sp is SupplyParameterParameter)
                {
                    SupplyParameterParameter sp_ = (SupplyParameterParameter)sp;
                    acfaPar = null;
                    Console.WriteLine("collectParameter -TRACE 2 " + "#" + sp_.Id_functor_app + sp_.Id_parameter);

                    pars.TryGetValue("#" + sp_.Id_functor_app + sp_.Id_parameter, out acfaPar);
                    if (acfaPar == null)
                    {
                        Console.WriteLine("collectParameter -TRACE 3 " + sp_.Id_argument);

                        if (pars.TryGetValue(sp_.Id_argument, out acfaPar))
                        {
                            parsSlice.Add(sp_.Id_parameter, acfaPar);
                            Console.WriteLine("collectParameter -TRACE 4 " + sp_.Id_parameter + " : " + acfaPar.Id_abstract);
                        }
                        else
                        {
                            AbstractComponentFunctorParameter acfp = br.ufc.pargo.hpe.backend.DGAC.BackEnd.acfpdao.retrieve(Id_abstract, sp_.Id_argument);
                            if (acfp == null)
                            {
                                acfp = br.ufc.pargo.hpe.backend.DGAC.BackEnd.acfpdao.retrieve(sp_.Id_abstract, sp_.Id_parameter);
                            }
                            acfaPar = br.ufc.pargo.hpe.backend.DGAC.BackEnd.acfadao.retrieve(acfp.Bounds_of);
                            parsSlice.Add(sp_.Id_parameter, acfaPar);
                            Console.WriteLine("collectParameter -TRACE 5 " + sp_.Id_parameter + " : " + acfaPar.Id_abstract);
                        }
                    }
                    else
                    {
                        Console.WriteLine("collectParameter -TRACE 6 " + "#" + sp_.Id_functor_app + sp_.Id_parameter + " : " + acfaPar.Id_abstract);
                        parsSlice.Add(sp_.Id_parameter, acfaPar);
                    }


                    /* else
                     * {
                     *  throw new Exception("ERROR !!!! collectParameters (Interface.cs)");
                     * }*/
                }

                collectFV(acfaPar, pars, parsSlice);
            }
        }