public void Run()
        {
            try {
                switch (scriptLanguage)
                {
                case ScriptLanguage.JScript:
                    scriptEngine = new JScript();
                    break;

                case ScriptLanguage.VBScript:
                    scriptEngine = new VBScript();
                    break;

                default:
                    throw new ClrPlusException("Invalid Script Language");
                }
                EXCEPINFO info;
                ActiveScriptParse.InitNew();
                ActiveScript.SetScriptSite(this);

                // add this object in
                GlobalMembers.Add("WScript", this);

                foreach (string key in GlobalMembers.Keys)
                {
                    ActiveScript.AddNamedItem(key, ScriptItem.IsVisible | ScriptItem.GlobalMembers);
                }

                ActiveScriptParse.ParseScriptText(ScriptText, null, IntPtr.Zero, null, 0, 0, 0, IntPtr.Zero, out info);
                ActiveScript.SetScriptState((uint)ScriptState.Connected);
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #2
0
    public void vibration_generation(double attenuation_rate)
    {
        vibrations.Clear();
        foreach (var t in population)
        {
            vibrations.Add(new Vibration(t.position));
        }
        double        sum  = 0.0;
        List <double> data = new List <double>();

        data.Resize(population.Count);
        for (int i = 0; i < dimension; ++i)
        {
            for (int j = 0; j < population.Count; ++j)
            {
                data[j] = population[j].position.solution[i];
            }

            sum += GlobalMembers.std_dev(data);
        }
        attenuation_base = sum / dimension;
        for (int i = 0; i < population.Count; ++i)
        {
            population[i].choose_vibration(vibrations, distances[i], attenuation_base * attenuation_rate);
        }
    }
Beispiel #3
0
        public Ipv4Address(string dottedDecimal)
        {
            uint offset = 0;

            value = GlobalMembers.readUint8(dottedDecimal, ref offset);
            if (offset == dottedDecimal.Length || dottedDecimal[offset] != '.')
            {
                throw new System.Exception("Invalid Ipv4 address string");
            }

            ++offset;
            value = value << 8 | GlobalMembers.readUint8(dottedDecimal, ref offset);
            if (offset == dottedDecimal.Length || dottedDecimal[offset] != '.')
            {
                throw new System.Exception("Invalid Ipv4 address string");
            }

            ++offset;
            value = value << 8 | GlobalMembers.readUint8(dottedDecimal, ref offset);
            if (offset == dottedDecimal.Length || dottedDecimal[offset] != '.')
            {
                throw new System.Exception("Invalid Ipv4 address string");
            }

            ++offset;
            value = value << 8 | GlobalMembers.readUint8(dottedDecimal, ref offset);
            if (offset < dottedDecimal.Length)
            {
                throw new System.Exception("Invalid Ipv4 address string");
            }
        }
        public bool read_from_tty(string password)
        {
            const char BACKSPACE = 127;

            password.reserve(max_password_size);
            while (password.Length < max_password_size)
            {
                int ch = GlobalMembers.getch();
                if (EOF == ch)
                {
                    return(false);
                }
                else if (ch == '\n' || ch == '\r')
                {
                    Console.Write("\n");
                    break;
                }
                else if (ch == BACKSPACE)
                {
                    if (!string.IsNullOrEmpty(password))
                    {
                        password.back() = '\0';
                        password.resize(password.Length - 1);
                        Console.Write("\b \b");
                    }
                }
                else
                {
                    password.push_back(ch);
                    Console.Write('*');
                }
            }

            return(true);
        }
Beispiel #5
0
    // The main function to check whether a given graph contains cycle or not
    public static int isCycle(GlobalMembers graph)
    {
        int V = graph.V;
        int E = graph.E;

        // Allocate memory for creating V sets
        subset[] subsets = new subset[V];
        for (int i = 0; i < subsets.Length; ++i)
        {
            subsets[i] = new subset();
        }

        for (int v = 0; v < V; ++v)
        {
            subsets[v].parent = v;
            subsets[v].rank   = 0;
        }

        // Iterate through all edges of graph, find sets of both
        // vertices of every edge, if sets are same, then there is
        // cycle in graph.
        for (int e = 0; e < E; ++e)
        {
            int x = find(subsets, graph.edge[e].src);
            int y = find(subsets, graph.edge[e].dest);

            if (x == y)
            {
                return(1);
            }

            Union(subsets, x, y);
        }
        return(0);
    }
Beispiel #6
0
    private void DelayedStart()
    {
        AppPath = Application.dataPath;

        // Init the build engine.
        Engine.skyMaterial   = skyMaterial;
        Engine.xrRigObject   = xrRigObject;
        Engine.xrPostProcess = xrPostProcess;
        Engine.Init();
        //GlobalMembers.ud.warp_on = 1;
        //GlobalMembers.boardfilename = "e4l1.map";

        //UnityEngine.XR.XRSettings.enabled = true;

        // This needs to be done in the main thread so we can do sound loading immediatly afterwords.
        GlobalMembers.conScript = new ConScript(new TrapEngine());
        SoundEngine.globalSoundEngine.LoadAllSounds();

        // Load in the game data.
        //Engine.initgroupfile("data.grp");
        //

        // Init the device
        Engine.setgamemode(0, 320, 200, 8);
        _texture = new Texture2D(Engine._device._screenbuffer._width, Engine._device._screenbuffer._height, TextureFormat.BGRA32, false);

        canvasImage.texture = _texture;

        GlobalMembers.DukeMain(""); // Get everything setup.

        Engine.palette.UpdatePaletteMainThread();

        handle = GCHandle.Alloc(Engine._device._screenbuffer.PresentedPixels, GCHandleType.Pinned);
    }
    public bool init(int argc, string[] argv)
    {
        if (!config.init(argc, argv))
        {
            return(false);
        }

        logger.setMaxLevel((Logging.Level)config.serviceConfig.logLevel);
        logger.setPattern("%D %T %L ");
        logger.addLogger(consoleLogger);

        Logging.LoggerRef log = new Logging.LoggerRef(logger.functorMethod, "main");

        if (!string.IsNullOrEmpty(config.serviceConfig.serverRoot))
        {
            GlobalMembers.changeDirectory(config.serviceConfig.serverRoot);
            Math.Log(Logging.Level.INFO) << "Current working directory now is " << config.serviceConfig.serverRoot;
        }

        fileStream.open(config.serviceConfig.logFile, std::ofstream.app);

        if (fileStream == null)
        {
            throw new System.Exception("Couldn't open log file");
        }

        fileLogger.attachToStream(fileStream);
        logger.addLogger(fileLogger);

        return(true);
    }
Beispiel #8
0
    public complex hTilde_0(int n_prime, int m_prime)
    {
        complex r = GlobalMembers.gaussianRandomVariable();
        float   t = phillips(n_prime, m_prime) / 2.0f;

        return(r * Mathf.Sqrt(t));
    }
Beispiel #9
0
        public static void generateViewFromSpend(Crypto.SecretKey spend, Crypto.SecretKey viewSecret, Crypto.PublicKey viewPublic)
        {
            Crypto.SecretKey viewKeySeed = new Crypto.SecretKey();

            GlobalMembers.keccak((ushort)spend, sizeof(Crypto.SecretKey), (ushort)viewKeySeed, sizeof(Crypto.SecretKey));

            Crypto.generate_deterministic_keys(viewPublic, viewSecret, viewKeySeed);
        }
        public bool read_password(bool verify, string msg)
        {
            clear();

            bool r;

            if (GlobalMembers.is_cin_tty())
            {
                Console.Write(InformationMsg(msg));

                if (verify)
                {
                    string password1;
                    string password2;
                    r = read_from_tty(password1);
                    if (r)
                    {
                        Console.Write(InformationMsg("Confirm your new password: "******"Passwords do not match, try again."));
                                Console.Write("\n");
                                clear();
                                return(read_password(true, msg));
                            }
                        }
                    }
                }
                else
                {
                    r = read_from_tty(m_password);
                }
            }
            else
            {
                r = read_from_file();
            }

            if (r)
            {
                m_empty = false;
            }
            else
            {
                clear();
            }

            return(r);
        }
Beispiel #11
0
    private void print_content()
    {
        var current_time = DateTime.Now;

        Console.Write("{0,5:D}\t{1:e3}\t{2:e3}\t{3:e3}\t{4:e3} ",
                      iteration, global_best.fitness, population_best_fitness, attenuation_base, mean_distance);
        Console.Write(GlobalMembers.get_time_string(current_time - start_time));
        Console.Write("\n");
    }
Beispiel #12
0
 public static Position init_position(Problem problem)
 {
     double[] solution = new double[problem.dimension];
     for (int i = 0; i < problem.dimension; ++i)
     {
         solution[i] = GlobalMembers.randu() * 200.0f - 100.0f;
     }
     return(new Position(solution.ToList(), 1E100));
 }
Beispiel #13
0
    static void InitEditor()
    {
        GameEngine.AppPath = Application.dataPath;

        Engine.Init();
        GlobalMembers.DukeMain(""); // Get everything setup.

        Engine.palette.UpdatePaletteMainThread();
    }
Beispiel #14
0
 public void random_walk(List <Vibration> vibrations)
 {
     for (int i = 0; i < position.solution.Count; ++i)
     {
         previous_move[i] *= GlobalMembers.randu();
         double target_position = dimension_mask[i] ? vibrations[RandomNumbers.NextNumber() % vibrations.Count].position.solution[i] : target_vibr.position.solution[i];
         previous_move[i]     += GlobalMembers.randu() * (target_position - position.solution[i]);
         position.solution[i] += previous_move[i];
     }
 }
Beispiel #15
0
 private void print_header()
 {
     Console.Write("               SSA starts at ");
     Console.Write(GlobalMembers.get_time_string());
     Console.Write("\n");
     Console.Write("==============================================================");
     Console.Write("\n");
     Console.Write(" iter\tbest fitness\tpop_fitness\tbase_dist\tmean_dist\ttime_elapsed");
     Console.Write("\n");
     Console.Write("==============================================================");
     Console.Write("\n");
 }
Beispiel #16
0
 public void mask_changing(double p_change, double p_mask)
 {
     if (GlobalMembers.randu() > Math.Pow(p_change, inactive_deg))
     {
         inactive_deg = 0;
         p_mask      *= GlobalMembers.randu();
         for (int i = 0; i < dimension_mask.Count; ++i)
         {
             dimension_mask[i] = (GlobalMembers.randu()) < p_mask;
         }
     }
 }
            // lhs > hrs

            // lhs > hrs
//C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#:
//ORIGINAL LINE: bool operator ()(const PendingTransactionInfo& lhs, const PendingTransactionInfo& rhs) const
            public static bool functorMethod(PendingTransactionInfo lhs, PendingTransactionInfo rhs)
            {
                CachedTransaction left  = lhs.cachedTransaction;
                CachedTransaction right = rhs.cachedTransaction;

                // price(lhs) = lhs.fee / lhs.blobSize
                // price(lhs) > price(rhs) -->
                // lhs.fee / lhs.blobSize > rhs.fee / rhs.blobSize -->
                // lhs.fee * rhs.blobSize > rhs.fee * lhs.blobSize
                ulong lhs_hi = new ulong();
                ulong lhs_lo = GlobalMembers.mul128(left.getTransactionFee(), right.getTransactionBinaryArray().size(), lhs_hi);
                ulong rhs_hi = new ulong();
                ulong rhs_lo = GlobalMembers.mul128(right.getTransactionFee(), left.getTransactionBinaryArray().size(), rhs_hi);

                return((lhs_hi > rhs_hi) || (lhs_hi == rhs_hi && lhs_lo > rhs_lo) || (lhs_hi == rhs_hi && lhs_lo == rhs_lo && left.getTransactionBinaryArray().size() < right.getTransactionBinaryArray().size()) || (lhs_hi == rhs_hi && lhs_lo == rhs_lo && left.getTransactionBinaryArray().size() == right.getTransactionBinaryArray().size() && lhs.receiveTime < rhs.receiveTime));
            }
        public void Prepare(PrerollContext context, Layer layer, SKMatrix ctm)
        {
            RasterCacheKey <Layer> cache_key = new RasterCacheKey <Layer>(layer, ctm);
            Entry entry = layer_cache_.First(x => x == cache_key).id(); // I used Linq, that aint going to be good for performance

            entry.access_count    = GlobalMembers.ClampSize(entry.access_count + 1, 0, threshold_);
            entry.used_this_frame = true;
            if (!entry.image.is_valid)
            {
                entry.image = GlobalMembers.Rasterize(context.gr_context, ctm, context.dst_color_space, checkerboard_images_, layer.paint_bounds(), (SKCanvas canvas) =>
                {
                    Layer.PaintContext paintContext = new Layer.PaintContext(canvas, null, context.texture_registry, context.raster_cache, context.checkerboard_offscreen_layers);
                    layer.Paint(paintContext);
                });
            }
        }
    //--------------------------------------------------------------------------------
    private bool print_pool_sh(List <string> args)
    {
        Console.Write("Pool short state: \n");
        var pool = m_core.getPoolTransactions();

        foreach (var tx in pool)
        {
            CryptoNote.CachedTransaction ctx = new CryptoNote.CachedTransaction(new Transaction(tx));
            Console.Write(GlobalMembers.printTransactionShortInfo(ctx));
            Console.Write("\n");
        }

        Console.Write("\n");

        return(true);
    }
        public void GetItemInfo([In, MarshalAs(UnmanagedType.BStr)] string pstrName, [In, MarshalAs(UnmanagedType.U4)] uint dwReturnMask, [Out, MarshalAs(UnmanagedType.IUnknown)] out object item, IntPtr ppti)
        {
            if (GlobalMembers.ContainsKey(pstrName))
            {
                item = GlobalMembers[pstrName];
            }
            else
            {
                item = null;
                return;
            }

            if (ppti != IntPtr.Zero)
            {
                Marshal.WriteIntPtr(ppti, Marshal.GetITypeInfoForType(item.GetType()));
            }
        }
        // Return true if the cache is generated.
        //
        // We may return false and not generate the cache if
        // 1. The picture is not worth rasterizing
        // 2. The matrix is singular
        // 3. The picture is accessed too few times
        public bool Prepare(GRContext context, SKPicture picture, SKMatrix transformation_matrix, SKColorSpace dst_color_space, bool is_complex, bool will_change)
        {
            if (!GlobalMembers.IsPictureWorthRasterizing(picture, will_change, is_complex))
            {
                // We only deal with pictures that are worthy of rasterization.
                return(false);
            }

            // Decompose the matrix (once) for all subsequent operations. We want to make
            // sure to avoid volumetric distortions while accounting for scaling.
            //MatrixDecomposition matrix = new MatrixDecomposition(transformation_matrix);

            //if (!matrix.IsValid())
            //{
            //    // The matrix was singular. No point in going further.
            //    return false;
            //}

            RasterCacheKey <UniqueEntry> cache_key = new RasterCacheKey <UniqueEntry>(new UniqueEntry(picture.UniqueId), transformation_matrix);

            Entry entry = picture_cache_.First(x => x.Equals(cache_key)).id(); // I used Linq, that aint going to be good for performance

            //C++ TO C# CONVERTER TODO TASK: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created:
            //ORIGINAL LINE: entry.access_count = ClampSize(entry.access_count + 1, 0, threshold_);
            entry.access_count    = GlobalMembers.ClampSize(entry.access_count + 1, 0, threshold_);
            entry.used_this_frame = true;

            if (entry.access_count < threshold_ || threshold_ == 0)
            {
                // Frame threshold has not yet been reached.
                return(false);
            }

            if (!entry.image.is_valid)
            {
                //C++ TO C# CONVERTER TODO TASK: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created:
                //ORIGINAL LINE: entry.image = RasterizePicture(picture, context, transformation_matrix, dst_color_space, checkerboard_images_);
                entry.image = GlobalMembers.RasterizePicture(picture, context, transformation_matrix, dst_color_space, checkerboard_images_);
            }
            return(true);
        }
Beispiel #22
0
        public static void Reset()
        {
            GlobalInstances.Clear();
            GlobalMembers.Clear();
            GlobalNames.Clear();
            GlobalFactories.Clear();

            Register <byte>(1);
            Register <sbyte>(1);
            Register <short>(1);
            Register <ushort>(1);
            Register <int>(1);
            Register <uint>(1);
            Register <long>(1);
            Register <ulong>(1);
            Register <float>(1.0f);
            Register <double>(1.0);
            Register("Foo");
            Register(Guid.Empty);
            Register(new DateTime(2020, 1, 1));
        }
    //--------------------------------------------------------------------------------
    private bool print_block_by_height(uint height)
    {
        if (height - 1 > m_core.getTopBlockIndex() != null)
        {
            Console.Write("block wasn't found. Current block chain height: ");
            Console.Write(m_core.getTopBlockIndex() + 1);
            Console.Write(", requested: ");
            Console.Write(height);
            Console.Write("\n");
            return(false);
        }

        var hash = m_core.getBlockHashByIndex(height - 1);

        Console.Write("block_id: ");
        Console.Write(hash);
        Console.Write("\n");
        GlobalMembers.print_as_json(m_core.getBlockByIndex(height - 1));

        return(true);
    }
        public void Prepare(PrerollContext context, Layer layer, SKMatrix ctm)
        {
            RasterCacheKey <Layer> cache_key = new RasterCacheKey <Layer>(layer, ctm);
            Entry entry = layer_cache_.First(x => x == cache_key).id(); // I used Linq, that aint going to be good for performance

            //C++ TO C# CONVERTER TODO TASK: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created:
            //ORIGINAL LINE: entry.access_count = ClampSize(entry.access_count + 1, 0, threshold_);
            entry.access_count    = GlobalMembers.ClampSize(entry.access_count + 1, 0, threshold_);
            entry.used_this_frame = true;
            if (!entry.image.is_valid)
            {
                //C++ TO C# CONVERTER TODO TASK: Only lambda expressions having all locals passed by reference can be converted to C#:
                //ORIGINAL LINE: entry.image = Rasterize(context->gr_context, ctm, context->dst_color_space, checkerboard_images_, layer->paint_bounds(), [layer, context](SKCanvas* canvas)
                //C++ TO C# CONVERTER TODO TASK: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created:
                entry.image = GlobalMembers.Rasterize(context.gr_context, ctm, context.dst_color_space, checkerboard_images_, layer.paint_bounds(), (SKCanvas canvas) =>
                {
                    Layer.PaintContext paintContext = new Layer.PaintContext(canvas, null, context.texture_registry, context.raster_cache, context.checkerboard_offscreen_layers);
                    layer.Paint(paintContext);
                });
            }
        }
    //--------------------------------------------------------------------------------
    private bool print_tx(List <string> args)
    {
        if (args.Count == 0)
        {
            Console.Write("expected: print_tx <transaction hash>");
            Console.Write("\n");
            return(true);
        }

        string str_hash = args[0];

        Crypto.Hash tx_hash = new Crypto.Hash();
        if (!parse_hash256(str_hash, tx_hash))
        {
            return(true);
        }

        List <Crypto.Hash> tx_ids = new List <Crypto.Hash>();

        tx_ids.Add(tx_hash);
        List <List <ushort> > txs        = new List <List <ushort> >();
        List <Crypto.Hash>    missed_ids = new List <Crypto.Hash>();

        m_core.getTransactions(tx_ids, txs, missed_ids);

        if (1 == txs.Count)
        {
            CryptoNote.CachedTransaction tx = new CryptoNote.CachedTransaction(new List <List <ushort> >(txs[0]));
            GlobalMembers.print_as_json(tx.getTransaction());
        }
        else
        {
            Console.Write("transaction wasn't found: <");
            Console.Write(str_hash);
            Console.Write('>');
            Console.Write("\n");
        }

        return(true);
    }
    //--------------------------------------------------------------------------------
    private bool print_block_by_hash(string arg)
    {
        Crypto.Hash block_hash = new Crypto.Hash();
        if (!parse_hash256(arg, block_hash))
        {
            return(false);
        }

        if (m_core.hasBlock(block_hash))
        {
            GlobalMembers.print_as_json(m_core.getBlockByHash(block_hash));
        }
        else
        {
            Console.Write("block wasn't found: ");
            Console.Write(arg);
            Console.Write("\n");
            return(false);
        }

        return(true);
    }
Beispiel #27
0
        public virtual void FunctorMethod(string category, Level level, DateTime time, string body)
        {
            if ((level <= logLevel) && disabledCategories.Count == 0)
            {
                string body2 = body;
                if (!string.IsNullOrEmpty(pattern))
                {
                    int insertPos = 0;
                    if (!string.IsNullOrEmpty(body2) && body2[0] == COLOR_DELIMETER)
                    {
                        int delimPos = body2.IndexOf(COLOR_DELIMETER, 1);
                        if (delimPos != -1)
                        {
                            insertPos = delimPos + 1;
                        }
                    }

                    body2 = body2.Insert(insertPos, GlobalMembers.FormatPattern(pattern, category, level, time));
                }

                DoLogString(body2);
            }
        }
            public Indiv mat(Indiv par2)
            {
                string child_chromo1 = "";
                string child_chromo2 = "";
                string child_chromo3 = "";
                int    len, l1 = par2.chromo.Length;
                int    l = chromo.Length;

                if (l1 < l)
                {
                    len = l1;
                }
                else
                {
                    len = l;
                }

                for (int i = 2; i < len; i++)
                {
                    double p = GlobalMembers.random_weight(0, 1);
                    //cout<<p<<" ";
                    if (p < 0.6)
                    {
                        child_chromo1 += chromo[i];
                    }

                    else if (p < 0.80)
                    {
                        child_chromo1 += par2.chromo[i];
                    }

                    else
                    {
                        child_chromo1 += (char)GlobalMembers.mutated_genes();
                    }
                }
                for (int i = 2; i < len; i++)
                {
                    double p = GlobalMembers.random_weight(0, 1);
                    if (p < 0.6)
                    {
                        child_chromo2 += chromo[i];
                    }

                    else if (p < 0.80)
                    {
                        child_chromo2 += par2.chromo[i];
                    }

                    else
                    {
                        child_chromo2 += (char)GlobalMembers.mutated_genes();
                    }
                }
                for (int i = 2; i < len; i++)
                {
                    double p = GlobalMembers.random_weight(0, 1);
                    if (p < 0.6)
                    {
                        child_chromo3 += chromo[i];
                    }

                    else if (p < 0.80)
                    {
                        child_chromo3 += par2.chromo[i];
                    }

                    else
                    {
                        child_chromo3 += (char)GlobalMembers.mutated_genes();
                    }
                }
                child_chromo1 = "0." + child_chromo1;
                child_chromo2 = "0." + child_chromo2;
                child_chromo3 = "0." + child_chromo3;
                //cout<<child_chromosome1<<" "<<child_chromosome2<<" "<<child_chromosome3<<" ";
                string c1 = child_chromo1;
                string c2 = child_chromo2;
                string c3 = child_chromo3;
                double number, number1, number2;

                Double.TryParse(c1, out number);
                Double.TryParse(c2, out number1);
                Double.TryParse(c3, out number2);
                Indiv ret = new Indiv(number, number1, number2);

                return(ret);
            }
        protected void Button1_Click(object sender, EventArgs e)
        {
            int n = 1;

            while (n > 0)
            {
                n--;
                con.Open();

                //  int n = 100;

                // int j = 1;
                //   for(int j=1;j<=50;j++)
                // {
                //RandomNumbers.Seed((uint)(time(0)));

                /*   double MU1 = GlobalMembers.random_weight(0, 1);
                 * double MU2 = GlobalMembers.random_weight(0, 1);
                 * double MU3 = GlobalMembers.random_weight(0, 1);
                 * // double a1 = 1;
                 * double NU1 = (double)1 - MU1;
                 * double NU2 = (double)1 - MU2;
                 * double NU3 = (double)1 - MU3;
                 *///    double w1=random_weight(0,1),w2=random_weight(0,1),w3=random_weight(0,1);

                //double MU=1-((1-pow(MU1,w1))*(1-pow(MU2,w2))*(1-pow(MU3,w3)));

                /*     double MU1 = Convert.ToDouble(Session["MU1"]);
                 *   double MU2 = Convert.ToDouble(Session["MU2"]);
                 *   double MU3 = Convert.ToDouble(Session["MU3"]);
                 *   double NU1 = Convert.ToDouble(Session["NU1"]);
                 *   double NU2 = Convert.ToDouble(Session["NU2"]);
                 *   double NU3 = Convert.ToDouble(Session["NU3"]);
                 */
                string        semail = Session["email"].ToString();
                string        sname  = Session["name"].ToString();
                SqlCommand    cmd    = new SqlCommand("Select MU_Aggregate,NU_Aggregate from LearningForm Where Email='" + semail + "'", con);
                SqlDataReader dr     = cmd.ExecuteReader();
                DataTable     dt     = new DataTable();
                dt.Load(dr);
                int flag = 1;
                if (dt.Rows.Count <= 0)
                {
                    //   ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please fill the Learning Style questionnaire first.')", true);
                    Session["flag"] = 0;
                    Response.Redirect("Learningform.aspx");
                }
                double MU1 = Convert.ToDouble(dt.Rows[0][0]);
                double NU1 = Convert.ToDouble(dt.Rows[0][1]);

                SqlCommand    cmd1 = new SqlCommand("Select MU,NU from PersonalityForm Where Email='" + semail + "'", con);
                SqlDataReader dr1  = cmd1.ExecuteReader();
                DataTable     dt1  = new DataTable();
                dt1.Load(dr1);

                if (dt1.Rows.Count <= 0)
                {
                    Session["flag"] = 0;
                    Response.Redirect("Personalityform.aspx");
                }
                double        MU2  = Convert.ToDouble(dt1.Rows[0][0]);
                double        NU2  = Convert.ToDouble(dt1.Rows[0][1]);
                SqlCommand    cmd2 = new SqlCommand("Select MU,NU from Knowledgeform Where Email='" + semail + "'", con);
                SqlDataReader dr2  = cmd2.ExecuteReader();
                DataTable     dt2  = new DataTable();
                dt2.Load(dr2);

                if (dt2.Rows.Count <= 0)
                {
                    Session["flag"] = 0;
                    Response.Redirect("Knowledgelevel.aspx");
                }
                double MU3 = Convert.ToDouble(dt2.Rows[0][0]);
                double NU3 = Convert.ToDouble(dt2.Rows[0][1]);

                double averageMU     = (MU1 + MU2 + MU3) / 3;
                double diffMU1       = MU1 - NU1;
                double diffMU2       = MU2 - NU2;
                double diffMU3       = MU3 - NU3;
                double averagediffMU = (diffMU1 + diffMU2 + diffMU3) / 3;
                int    generation    = 0;

                List <Individual> population = new List <Individual>();
                bool         found           = false;
                List <Indiv> pop             = new List <Indiv>();
                for (int i = 0; i < DefineConstants.POPULATION_SIZE; i++)
                {
                    //string gnome = create_gnome();
                    population.Add(new Individual(MU1, MU2, MU3));
                    pop.Add(new Indiv(NU1, NU2, NU3));
                    //cout<<population[i].fitness<<" ";
                }

                while (!found)
                {
                    if (generation == 100)
                    {
                        found = true;
                        break;
                    }
                    // List<int> integers = new List<int>();
                    List <Individual> new_generation = new List <Individual>();
                    List <Indiv>      new_gen        = new List <Indiv>();
                    int s = (80 * DefineConstants.POPULATION_SIZE) / 100;
                    for (int i = 10; i < s + 10; i++)
                    {
                        new_generation.Add(population[i]);
                        new_gen.Add(pop[i]);
                        // cout<<population[i].fitness<<" ";
                    }
                    s = (20 * DefineConstants.POPULATION_SIZE) / 100;
                    for (int i = 0; i < s; i++)
                    {
                        //  int len = population.size();
                        int        r       = GlobalMembers.random_num(0, 5);
                        Individual parent1 = population[r];
                        Indiv      par1    = pop[r];
                        //cout<<population[r].fitness<<" ";
                        r = GlobalMembers.random_num(0, 5);
                        Individual parent2 = population[r];
                        Indiv      par2    = pop[r];
                        //cout<<population[r].fitness<<" ";
                        Individual offspring = parent1.mate(parent2);
                        Indiv      offsp     = par1.mat(par2);
                        new_generation.Add(offspring);
                        new_gen.Add(offsp);
                        //cout<<new_generation[i].fitness<<" ";
                    }
                    population = new_generation;
                    pop        = new_gen;
                    //	cout<< "Generation: " << generation << "\t";
                    //cout<< population[0].chromosome <<endl;

                    generation++;
                }
                //cout<< generation << "\t";
                double X = Convert.ToDouble(population[0].chromosome);
                double Y = Convert.ToDouble(pop[0].chromo);
                //System.Diagnostics.Debug.WriteLine("MU-" + X);
                // System.Diagnostics.Debug.WriteLine("NU-" + Y);
                if (X + Y > 1)
                {
                    Y = (double)1 - X;
                }
                Session["Mu"] = X;
                Session["Nu"] = Y;
                knn a = new knn();
                a.KNN();
                int c;
                c = Convert.ToInt32(Session["class"]);

                SqlCommand com = new SqlCommand("insert into Class (Email,Name,MU,NU,Class,Generation,Mu1,Mu2,Mu3,AverageMu,Mu1diff,Mu2diff,Mu3diff,averageMudiff) values('" + semail + "','" + sname + "','" + X + "','" + Y + "','" + c + "','" + generation + "','" + MU1 + "','" + MU2 + "','" + MU3 + "','" + averageMU + "','" + diffMU1 + "','" + diffMU2 + "','" + diffMU3 + "','" + averagediffMU + "')", con);
                com.ExecuteNonQuery();
                //}



                //    Response.Redirect("knn.aspx");
                string cl;
                if (c == 1)
                {
                    cl = "Low";
                }
                else if (c == 2)
                {
                    cl = "Low-Medium";
                }
                else if (c == 3)
                {
                    cl = "Medium";
                }
                else if (c == 4)
                {
                    cl = "Medium-High";
                }
                else
                {
                    cl = "High";
                }


                con.Close();
            }
            //Response.Redirect("WebForm2.aspx");
            //Response.Write("<script language='javascript'>window.alert('You belong to class "+cl+"');window.location='WebForm2.aspx';</script>");
        }
Beispiel #30
0
    // Update is called once per frame
    void Update()
    {
        if (delayedStart)
        {
            DelayedStart();
            delayedStart = false;
        }

        Engine.ClearDelayedRotateSprites();

        GlobalMembers.anyKeyDown = Input.anyKeyDown;

        if (Input.GetKey(KeyCode.LeftShift))
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_LeftShift)] = true;
        }
        else
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_LeftShift)] = false;
        }


        if (Input.GetKeyDown(KeyCode.Escape))
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_Escape)] = true;
        }
        else if (Input.GetKeyUp(KeyCode.Escape))
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_Escape)] = false;
        }

        if (Input.GetKey(KeyCode.Return))
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_Return)] = true;
        }
        else
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_Return)] = false;
        }

        if (Input.GetKey(KeyCode.LeftBracket))
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_OpenBracket)] = true;
        }
        else
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_OpenBracket)] = false;
        }

        if (Input.GetKey(KeyCode.RightBracket))
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_CloseBracket)] = true;
        }
        else
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_CloseBracket)] = false;
        }

        if (Input.GetKey(KeyCode.UpArrow))
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_UpArrow)] = true;
        }
        else
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_UpArrow)] = false;
        }

        if (Input.GetKey(KeyCode.DownArrow))
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_DownArrow)] = true;
        }
        else
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_DownArrow)] = false;
        }

        if (Input.GetKey(KeyCode.LeftArrow))
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_LeftArrow)] = true;
        }
        else
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_LeftArrow)] = false;
        }

        if (Input.GetKey(KeyCode.RightArrow))
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_RightArrow)] = true;
        }
        else
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_RightArrow)] = false;
        }

        if (Input.GetKey(KeyCode.Space))
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_Space)] = true;
        }
        else
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_Space)] = false;
        }


        if (Input.GetKey(KeyCode.C))
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_C)] = true;
        }
        else
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_C)] = false;
        }

        if (Input.GetKey(KeyCode.LeftControl))
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_LeftControl)] = true;
        }
        else
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_LeftControl)] = false;
        }

        if (Input.GetKey(KeyCode.E))
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_E)] = true;
        }
        else
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_E)] = false;
        }

        if (Input.GetKey(KeyCode.R))
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_R)] = true;
        }
        else
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_R)] = false;
        }

        if (Input.GetKey(KeyCode.T))
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_T)] = true;
        }
        else
        {
            GlobalMembers.KB_KeyDown[(DefineConstants.sc_T)] = false;
        }

        for (int i = 0; i <= 9; i++)
        {
            if (Input.GetKey(KeyCode.Alpha0 + i))
            {
                GlobalMembers.KB_KeyDown[(DefineConstants.sc_0 + i)] = true;
            }
            else
            {
                GlobalMembers.KB_KeyDown[(DefineConstants.sc_0 + i)] = false;
            }
        }


        if (GlobalMembers.totalclock == 0)
        {
            dukeClock = 1.0f;
            GlobalMembers.totalclock = 1;
        }
        else
        {
            dukeClock += Time.deltaTime;
            GlobalMembers.totalclock = (int)(dukeClock * 120.0f);
        }

        GlobalMembers.RunState();

        GlobalMembers.faketimerhandler();

        if (Engine.board != null && Engine.board.render3D != null)
        {
            Engine.board.render3D.DisplayRoom(Engine.board.globalcursectnum);
        }


        // IntPtr pointer = handle.AddrOfPinnedObject();
        // _texture.LoadRawTextureData(pointer, Engine._device._screenbuffer._width * Engine._device._screenbuffer._height * 4);
        // _texture.Apply();

        //  Array.Clear(Engine._device._screenbuffer.Pixels, 0, Engine._device._screenbuffer.Pixels.Length);
    }