Beispiel #1
0
 public Modifier(float baseValue, Dictionary <string, float> modifiers, CalculateMode mode = CalculateMode.MULTIPLY)
 {
     _baseValue = baseValue;
     _modifiers = modifiers;
     ModifyMode = mode;
     RefreshCachedValue();
 }
Beispiel #2
0
 /// <summary>
 /// проверка двух связей и возможно связывание
 /// </summary>
 /// <param name="l"></param>
 /// <param name="r"></param>
 /// <param name="CompareDateTime"></param>
 /// <returns></returns>
 private bool Calculate_One(QSO l, QSO r, CalculateMode mode)
 {
     // совпадение всех полей кроме RST
     if (l.Raw.RecvCall == r.Raw.SendCall &&
         l.Raw.SendCall == r.Raw.RecvCall &&
         l.Feq == r.Feq &&
         //(l.Raw.Mode == r.Raw.Mode) &&
         ((l.Raw.Mode == r.Raw.Mode && l.Raw.Mode == "CW") || (l.Raw.Mode != "CW" && r.Raw.Mode != "CW")) &&
         Util.AsNumeric(l.Raw.SendExch1) == Util.AsNumeric(r.Raw.RecvExch1) &&
         Util.AsNumeric(l.Raw.SendExch2) == Util.AsNumeric(r.Raw.RecvExch2) &&
         Util.AsNumeric(l.Raw.SendExch3) == Util.AsNumeric(r.Raw.RecvExch3) &&
         Util.AsNumeric(l.Raw.RecvExch1) == Util.AsNumeric(r.Raw.SendExch1) &&
         Util.AsNumeric(l.Raw.RecvExch2) == Util.AsNumeric(r.Raw.SendExch2) &&
         Util.AsNumeric(l.Raw.RecvExch3) == Util.AsNumeric(r.Raw.SendExch3) &&
         (mode == CalculateMode.withoutdate || (mode == CalculateMode.withdate && l.DateTime == r.DateTime)) &&
         (Config.rst_check == 0 || (Config.rst_check == 1 &&
                                    Util.AsNumeric(l.Raw.SendRST) == Util.AsNumeric(r.Raw.RecvRST) &&
                                    Util.AsNumeric(l.Raw.RecvRST) == Util.AsNumeric(r.Raw.SendRST))) &&
         Coordinate.ValidateLocator(l.Raw.SendExch2) == true &&
         Coordinate.ValidateLocator(l.Raw.RecvExch2) == true)
     // TODO: где то нужно сделать правильно проверку локаторов выше две строки
     {
         //l.Errors.Clear();
         //r.Errors.Clear();
         if (mode == CalculateMode.withdate)
         {
             l.Errors.Add("=[" + r.Raw.SendCall + " QSO:" + r.Raw.Number + " " + r.DateTime.ToString("HHmm") + "]");
             r.Errors.Add("=[" + l.Raw.SendCall + " QSO:" + l.Raw.Number + " " + l.DateTime.ToString("HHmm") + "]");
         }
         else
         {
             l.Errors.Add("±[" + r.Raw.SendCall + " QSO:" + r.Raw.Number + " " + r.DateTime.ToString("HHmm") + "]");
             r.Errors.Add("±[" + l.Raw.SendCall + " QSO:" + l.Raw.Number + " " + l.DateTime.ToString("HHmm") + "]");
         }
         if (Util.AsNumeric(l.Raw.SendRST) != Util.AsNumeric(r.Raw.RecvRST))
         {
             l.Errors.Add("Partner warning (" + l.Raw.SendRST + "/" + r.Raw.RecvRST + ")");
             r.Errors.Add("Receive warning (" + l.Raw.SendRST + "/" + r.Raw.RecvRST + ")");
         }
         if (Util.AsNumeric(l.Raw.RecvRST) != Util.AsNumeric(r.Raw.SendRST))
         {
             l.Errors.Add("Receive warning (" + r.Raw.SendRST + "/" + l.Raw.RecvRST + ")");
             r.Errors.Add("Partner warning (" + r.Raw.SendRST + "/" + l.Raw.RecvRST + ")");
         }
         l.LinkedQSO   = r;
         l.Counters.OK = true;
         r.LinkedQSO   = l;
         r.Counters.OK = true;
         return(true);
     }
     return(false);
 }
Beispiel #3
0
        /// <summary>
        /// Calculates output. Can also calculate and store all neurons outputs and act. function derivatives.
        /// </summary>
        /// <exception cref="ArgumentException">If CalculateDerivatives is on and any Activation Function is not differentiable</exception>
        /// <remarks>
        /// You should usually provide proper mode enum.
        /// </remarks>
        /// <seealso cref="CalculateMode"/>
        /// <param name="input"></param>
        /// <returns>Output Vector</returns>
        public Vector <double> CalculateOutput(Vector <double> input, CalculateMode mode = CalculateMode.NetworkOutput)
        {
            if (mode.HasFlag(CalculateMode.AllOutputs))
            {
                LastOutputs[0] = Vector <double> .Build.DenseOfVector(input); //copy of
            }
            Vector <double> neuronSums;
            Vector <double> output = Vector <double> .Build.Dense(1); //initial unused value

            for (int layerIndex = 0; layerIndex < NumberOfLayers; layerIndex++)
            {
                neuronSums = (input.ToRowMatrix() * Layers[layerIndex].Weights).Row(0);
                int biasModifier = 0;
                if (layerIndex != NumberOfLayers - 1 && IsBiasExisting)
                {
                    biasModifier = 1;
                }
                output = Vector <double> .Build.Dense(neuronSums.Count() + biasModifier);

                output[0] = 1; // if biasModifier is 0, that would be overwritten
                //calculate activation functions
                for (int outputIndex = biasModifier; outputIndex < neuronSums.Count() + biasModifier; outputIndex++)
                {
                    output[outputIndex] = Layers[layerIndex].ActivationFunction.Calculate(neuronSums[outputIndex - biasModifier]);
                    if (mode.HasFlag(CalculateMode.Derivatives))
                    {
                        var differentiableFunction = Layers[layerIndex].ActivationFunction as IDifferentiable;
                        LastDerivatives[layerIndex][outputIndex - biasModifier] = differentiableFunction.CalculateDerivative(neuronSums[outputIndex - biasModifier]);
                    }
                }

                if (mode.HasFlag(CalculateMode.AllOutputs))
                {
                    LastOutputs[layerIndex + 1] = Vector <double> .Build.DenseOfVector(output); //copy of, +1 because first place is occupied by input
                }
                input = output;
            }
            return(output);
        }
Beispiel #4
0
 private void add_Click(object sender, EventArgs e)
 {
     _calculateMode = CalculateMode.Add;
 }
Beispiel #5
0
 private void minus_Click(object sender, EventArgs e)
 {
     _calculateMode = CalculateMode.Minus;
 }
Beispiel #6
0
 private void divide_Click(object sender, EventArgs e)
 {
     _calculateMode = CalculateMode.Divide;
 }
Beispiel #7
0
 private void multiply_Click(object sender, EventArgs e)
 {
     _calculateMode = CalculateMode.Multi;
 }
Beispiel #8
0
 public Form1(CalculateMode calculateMode)
 {
     _calculateMode = calculateMode;
     InitializeComponent();
 }
Beispiel #9
0
        public static void Main(string[] args)
        {
            ICollection <(bool nearCenter, int[] neighboursIndexes)>?configuration;

            Console.WriteLine("Welcome to SporeCity emulator");
            Console.WriteLine("=============================");

            #region GetLayoutConfiguration

            while (true)
            {
                Console.WriteLine("Please enter your city layout or select from available");
                Console.WriteLine("=============================");
                Console.WriteLine("Layout format {[index of neighbours | 'C' for near center]}");
                Console.WriteLine("Example: {1,2,3};{2,3,C}");
                Console.WriteLine("=============================");
                Console.WriteLine("Available layouts:");
                Console.WriteLine("(s), Space Stage");
                Console.WriteLine("(ca), Civilization Type A");
                Console.WriteLine("(cb), Civilization Type B");
                Console.WriteLine("(cc), Civilization Type C");
                Console.WriteLine("(cd), Civilization Type D");
                Console.WriteLine("(ce), Civilization Type E");
                Console.WriteLine("=============================");
                Console.Write(">:");
                var input = Console.ReadLine() ?? "";
                if (input.StartsWith("s"))
                {
                    configuration = new List <(bool nearCenter, int[] neighboursIndexes)>
                    {
                        (true, new[] { 1, 5 }),
                        (true, new[] { 0, 6, 7 }),
                        (true, new[] { 7, 8 }),
                        (true, new[] { 8, 9 }),
                        (true, new[] { 5, 10 }),
                        (false, new[] { 0, 4, 10 }),
                        (false, new[] { 1 }),
                        (false, new[] { 1, 2 }),
                        (false, new[] { 2, 3, 9 }),
                        (false, new[] { 3, 8, 10 }),
                        (false, new[] { 4, 5, 9 })
                    };
                    break;
                }

                if (input.StartsWith("ca"))
                {
                    configuration = new List <(bool nearCenter, int[] neighboursIndexes)>
                    {
                        (false, new[] { 1 }),
                        (true, new[] { 0, 2, 3 }),
                        (false, new[] { 1, 3 }),
                        (false, new[] { 1, 2, 4, 6 }),
                        (false, new[] { 3, 5 }),
                        (false, new[] { 4, 6, 7 }),
                        (true, new[] { 3, 5, 7, 8 }),
                        (false, new[] { 5, 6 }),
                        (true, new[] { 6, 9, 10 }),
                        (false, new[] { 8, 10 }),
                        (false, new[] { 8, 9 })
                    };
                    break;
                }

                if (input.StartsWith("cb"))
                {
                    configuration = new List <(bool nearCenter, int[] neighboursIndexes)>
                    {
                        (true, new[] { 1 }),
                        (true, new[] { 0 }),
                        (false, new[] { 3 }),
                        (true, new[] { 2, 4 }),
                        (true, new[] { 3 })
                    };
                    break;
                }

                if (input.StartsWith("cc"))
                {
                    configuration = new List <(bool nearCenter, int[] neighboursIndexes)>
                    {
                        (true, new[] { 1 }),
                        (false, new[] { 0, 2 }),
                        (true, new[] { 1, 3 }),
                        (true, new[] { 2, 4 }),
                        (true, new[] { 3 })
                    };
                    break;
                }

                if (input.StartsWith("cd"))
                {
                    configuration = new List <(bool nearCenter, int[] neighboursIndexes)>
                    {
                        (false, new[] { 1 }),
                        (true, new[] { 0, 2 }),
                        (true, new[] { 1, 3, 6 }),
                        (false, new[] { 2, 4, 5 }),
                        (false, new[] { 3 }),
                        (false, new[] { 3 }),
                        (true, new[] { 2, 7 }),
                        (true, new[] { 6, 8, 9 }),
                        (false, new[] { 7, 9 }),
                        (false, new[] { 7, 8, 10 }),
                        (false, new[] { 9 })
                    };
                    break;
                }

                if (input.StartsWith("ce"))
                {
                    configuration = new List <(bool nearCenter, int[] neighboursIndexes)>
                    {
                        (true, new[] { 1 }),
                        (true, new[] { 0, 2 }),
                        (true, new[] { 1, 3 }),
                        (true, new[] { 2, 4 }),
                        (true, new[] { 3 }),
                    };
                    break;
                }

                if (!new Regex(@"^(?:{(?:[0-9Cc]+,)*[0-9Cc]+};)*(?:{(?:[0-9Cc]+,)*[0-9Cc]+})$").IsMatch(input ?? ""))
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Error: layout is not valid");
                    Console.ForegroundColor = ConsoleColor.White;
                }
                else
                {
                    configuration = input !.Split(";")
                                    .Select(place => place.Substring(1, place.Length - 2))
                                    .Select(place =>
                    {
                        var parts      = place.Split(",");
                        var indexes    = parts.Where(i => int.TryParse(i, out _)).Select(int.Parse).ToArray();
                        var nearCenter = parts.Any(i => i.ToLower().Equals("c"));

                        return(nearCenter, indexes !);
                    })
                                    .ToList();

                    break;
                }
            }

            int?          minWork = null;
            int?          minFun  = null;
            CalculateMode mode;

            #endregion

            #region GetMode

            while (true)
            {
                Console.WriteLine("Please enter mode number of leave blank for default (0)");
                Console.WriteLine("=============================");
                Console.WriteLine("Available modes:");
                Console.WriteLine("(0), Maximize work, keeping moral > 0");
                Console.WriteLine("(1), Maximize work 24/7 :(");
                Console.WriteLine("(2), Maximize moral, keeping work > 0");
                Console.WriteLine("(3), No working at all :'))");
                Console.WriteLine("(4), Input minimum values for work and moral");
                Console.WriteLine("=============================");
                Console.Write(">:");
                var input = Console.ReadLine() ?? "0";

                input = input.Length > 0 ? input : "0";

                if (CalculateMode.TryParse(input, out mode))
                {
                    break;
                }

                if (mode == CalculateMode.MinValues)
                {
                    while (true)
                    {
                        Console.WriteLine("Please enter min value for work or leave blank");
                        Console.Write(">:");
                        input = Console.ReadLine() ?? "0";

                        if (int.TryParse(input, out var _minWork))
                        {
                            minWork = _minWork;
                            break;
                        }
                    }

                    while (true)
                    {
                        Console.WriteLine("Please enter min value for moral or leave blank");
                        Console.Write(">:");
                        input = Console.ReadLine() ?? "0";

                        if (int.TryParse(input, out var _minFun))
                        {
                            minFun = _minFun;
                            break;
                        }
                    }
                }
            }

            #endregion

            #region GetMaxBuildingCount

            var maxBuildingsCount = configuration.Count;

            while (false)
            {
                Console.WriteLine("Please max buildings count or leave for blank");
                Console.Write(">:");
                var input = Console.ReadLine() ?? configuration.Count.ToString();
                if (int.TryParse(input, out maxBuildingsCount))
                {
                    break;
                }
            }

            #endregion

            try
            {
                var generator = new Generator(configuration);
                // var (score, layout) = generator.TestLayout(new []
                // {
                //     BuildingType.House,
                //     BuildingType.Work,
                //     BuildingType.Work,
                //     BuildingType.Fun,
                //     BuildingType.Work,
                //     BuildingType.Work,
                //     BuildingType.House,
                //     BuildingType.House,
                //     BuildingType.House,
                //     BuildingType.Fun,
                //     BuildingType.House,
                // });
                var(score, layout) = generator.GetBestLayouts(mode, minWork, minFun);

                Console.WriteLine($"work units: {score.work}, moral: {score.moral}");
                Console.WriteLine(string.Join("\n",
                                              layout.Take(20).Select(tuple => tuple.layout + $"| {tuple.price}$$")));
            }
            catch (IndexOutOfRangeException e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(
                    "Error: layout contains wrong indexes, check and try again. Remark: indexes starts from 0, not 1");
                Console.ForegroundColor = ConsoleColor.White;
            }

            Console.WriteLine("");
            Console.WriteLine("To exit press any key...");
            Console.ReadLine();
        }