예제 #1
0
        private void ArbitrageBtn_Click(object sender, EventArgs e)
        {
            OutputTxt.Text = "";
            Digraph graph = new Digraph();
            Parser  p     = new Parser();

            graph = p.Parse(FilePathTxt.Text, ref OutputTxt);

            if (!double.TryParse(ArbitrageAmountTxt.Text, out double moneyAtSource))
            {
                OutputTxt.Text = "Initial amount of money has to be a number";
            }
            else
            {
                var arbitrage = new Arbitrage(graph);
                List <CurrencyVertex> path = arbitrage.Find(moneyAtSource);
                string result;
                if (path != null)
                {
                    result = arbitrage.GenerateOutput(path, moneyAtSource);
                }
                else
                {
                    result = "No arbitrage opportunity detected";
                }
                OutputTxt.Text = result;
            }
            GraphImg.Focus();
        }
예제 #2
0
        private void CurrencyBtn_Click(object sender, EventArgs e)
        {
            OutputTxt.Text = "";
            Digraph graph = new Digraph();
            Parser  p     = new Parser();

            graph = p.Parse(FilePathTxt.Text, ref OutputTxt);

            CurrencyVertex from = graph.nodes.Find(x => x.Symbol == FromTxt.Text);
            CurrencyVertex to   = graph.nodes.Find(x => x.Symbol == ToTxt.Text);

            if (from == null)
            {
                OutputTxt.Text = "There is no such currency in the input file: " + FromTxt.Text;
            }
            else if (to == null)
            {
                OutputTxt.Text = "There is no such currency in the input file: " + ToTxt.Text;
            }
            else if (!double.TryParse(ExchangeAmountTxt.Text, out double moneyAtSource))
            {
                OutputTxt.Text = "Initial amount of money has to be a number";
            }
            else if (from.Equals(to))
            {
                OutputTxt.Text = "There is no need to convert " + from.Symbol + " to " + to.Symbol + ":)";
            }
            else
            {
                var exchange = new BestExchange(graph);
                try
                {
                    List <CurrencyVertex> path = exchange.Find(from, to, moneyAtSource, out double moneyAtFinish);
                    if (path == null)
                    {
                        OutputTxt.Text = "There is no exchange possible between given currencies";
                    }
                    else
                    {
                        var outputText = exchange.GenerateOutput(path);
                        OutputTxt.Text = outputText;
                    }
                }
                catch (OutOfMemoryException)
                {
                    OutputTxt.Text = "There is an infinite arbitrage on the way!";
                }
            }
            GraphImg.Focus();
        }
예제 #3
0
        private void FileBtn_Click(object sender, EventArgs e)
        {
            OutputTxt.Text = "";
            Digraph graph = new Digraph();

            GraphImg.Image = GraphImg.InitialImage;
            OpenFileDialog ofd = new OpenFileDialog
            {
                Filter = "TXT|*.txt"
            };

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                FilePathTxt.Text = ofd.FileName;
            }

            Parser p = new Parser();

            graph          = p.Parse(FilePathTxt.Text, ref OutputTxt);
            GraphImg.Image = Image.FromFile(graph.SaveGraphAsImg(IMG_PATH));
            GraphImg.Focus();
        }