Esempio n. 1
0
        public void guardaSimilitudes(int[] usuarios, double[,] similitud)
        {
            int    top             = 20;//guarda los mejores top
            double similitudMinima = 0.5;

            limpiaUsuarioRecomendacion();
            for (int i = 0; i < usuarios.Length; i++)
            {
                PriotiryQueue <CorrelacionUsuario> pq = new PriotiryQueue <CorrelacionUsuario>(invertida: true);
                for (int j = 0; j < usuarios.Length; j++)
                {
                    if (i != j && similitud[i, j] >= similitudMinima)
                    {
                        CorrelacionUsuario nuevo = new CorrelacionUsuario();
                        nuevo.u1          = usuarios[i];
                        nuevo.u2          = usuarios[j];
                        nuevo.correlacion = similitud[i, j];
                        pq.push(nuevo);
                        if (pq.count > top)
                        {
                            pq.pop();
                        }
                    }
                }
                StringBuilder command = new StringBuilder();
                command.Append("INSERT INTO SimulacionKarelotitlan.DBO.UsuarioRecomendacion (u1,u2,correlacion) VALUES  ");
                int cout = 0;
                while (!pq.empty)
                {
                    var elem = pq.pop();
                    if (cout != 0)
                    {
                        command.Append(",");
                    }
                    command.Append("(");
                    command.Append(elem.u1.ToString());
                    command.Append(",");
                    command.Append(elem.u2.ToString());
                    command.Append(",");
                    command.Append(elem.correlacion.ToString());
                    command.Append(")");
                    cout++;
                }
                command.Append(";");
                if (cout > 0)
                {
                    SqlConnection sqlConnection = new SqlConnection(connectionString);
                    SqlCommand    cmd           = new SqlCommand();
                    cmd.CommandText = command.ToString();
                    cmd.Connection  = sqlConnection;
                    sqlConnection.Open();
                    cmd.ExecuteNonQuery();
                    sqlConnection.Close();
                }
            }
        }
Esempio n. 2
0
        private void testPriorityQueue()
        {
            StringBuilder       log         = new StringBuilder();
            Random              rn          = new Random(123);
            PriotiryQueue <int> pq          = new PriotiryQueue <int>(invertida: false);
            PriotiryQueue <int> pqInvertida = new PriotiryQueue <int>(invertida: true);

            for (int i = 0; i < 10; i++)
            {
                int r = rn.Next() % 100;
                log.Append(r.ToString());
                log.Append(",");
                pq.push(r);
                pqInvertida.push(r);
            }
            log.Append("\r\n");
            while (!pq.empty)
            {
                log.Append(pq.top().ToString());
                pq.pop();
                log.Append(",");
            }
            log.Append("\r\n");
            while (!pqInvertida.empty)
            {
                log.Append(pqInvertida.top().ToString());
                pqInvertida.pop();
                log.Append(",");
            }
            log.Append("\r\n");
            txtLog.AppendText(log.ToString());
        }
Esempio n. 3
0
        public void guardaAnalisis(int[] usuarios, int[,] inversiones, int[,] iguales, int[,] complemento, double[,] scroe)
        {
            int top = 10; // guarda los mejores top

            limpiaInversion();
            for (int i = 0; i < usuarios.Length; i++)
            {
                PriotiryQueue <AnalisisUsuarioInversion> pq = new PriotiryQueue <AnalisisUsuarioInversion>(invertida: true);
                for (int j = 0; j < usuarios.Length; j++)
                {
                    AnalisisUsuarioInversion nuevo = new AnalisisUsuarioInversion();
                    nuevo.u1          = usuarios[i];
                    nuevo.u2          = usuarios[j];
                    nuevo.inversiones = inversiones[i, j];
                    nuevo.iguales     = iguales[i, j];
                    nuevo.complemento = complemento[i, j];
                    nuevo.score       = scroe[i, j];
                    pq.push(nuevo);
                    if (pq.count > top)
                    {
                        pq.pop();
                    }
                }
                StringBuilder command = new StringBuilder();
                command.Append("INSERT INTO SimulacionKarelotitlan.DBO.Inversion (u1,u2,inversiones,iguales,complemento) VALUES  ");
                int count = 0;
                while (!pq.empty)
                {
                    var elem = pq.pop();
                    if (count != 0)
                    {
                        command.Append(",");
                    }
                    command.Append("(");
                    command.Append(elem.u1.ToString());
                    command.Append(",");
                    command.Append(elem.u2.ToString());
                    command.Append(",");
                    command.Append(elem.inversiones.ToString());
                    command.Append(",");
                    command.Append(elem.iguales.ToString());
                    command.Append(",");
                    command.Append(elem.complemento.ToString());
                    command.Append(")");
                    count++;
                }

                command.Append(";");
                SqlConnection sqlConnection = new SqlConnection(connectionString);
                SqlCommand    cmd           = new SqlCommand();
                cmd.CommandText = command.ToString();
                cmd.Connection  = sqlConnection;
                sqlConnection.Open();
                cmd.ExecuteNonQuery();
                sqlConnection.Close();

                /* Comentando la version que guarda todos los resultados.
                 * int salto = 100;
                 * for (int jtemp = 0; jtemp < usuarios.Length; jtemp += salto)
                 * {
                 *  StringBuilder command = new StringBuilder();
                 *  command.Append("INSERT INTO SimulacionKarelotitlan.DBO.Inversion (u1,u2,inversiones,iguales,complemento) VALUES  ");
                 *
                 *  for (int j = jtemp;j<jtemp+salto && j < usuarios.Length; j++)
                 *  {
                 *      if ((j%salto) != 0)
                 *      {
                 *          command.Append(",");
                 *      }
                 *      command.Append("(");
                 *      command.Append(usuarios[i].ToString());
                 *      command.Append(",");
                 *      command.Append(usuarios[j].ToString());
                 *      command.Append(",");
                 *      command.Append(inversiones[i, j].ToString());
                 *      command.Append(",");
                 *      command.Append(iguales[i, j].ToString());
                 *      command.Append(",");
                 *      command.Append(complemento[i, j].ToString());
                 *      command.Append(")");
                 *  }
                 *
                 *  command.Append(";");
                 *  SqlConnection sqlConnection = new SqlConnection(connectionString);
                 *  SqlCommand cmd = new SqlCommand();
                 *  cmd.CommandText = command.ToString();
                 *  cmd.Connection = sqlConnection;
                 *  sqlConnection.Open();
                 *  cmd.ExecuteNonQuery();
                 *  sqlConnection.Close();
                 * }*/
            }
        }