コード例 #1
0
        public async Task <Differential> AddDifferential(Differential differential)
        {
            // fluent validation - jobId nao pode ser nulo
            if (differential == null)
            {
                return(null);
            }
            else
            {
                differential.Id = Guid.NewGuid();

                await _context.Differentials.AddAsync(differential);

                await _context.SaveChangesAsync();

                return(differential);
            }
        }
コード例 #2
0
    // Initialisation
    private void Start()
    {
        im     = GetComponent <InputManager>();
        rb     = GetComponent <Rigidbody>();
        ty     = GetComponent <Tyres>();
        engine = GetComponent <Engine>();
        trans  = GetComponent <Transmission>();
        aero   = GetComponent <Aerodynamics>();
        brakes = GetComponent <Brakes>();
        diff   = GetComponent <Differential>();
        steer  = GetComponent <Steering>();
        wheels = GetComponent <Wheels>();

        if (CM)
        {
            rb.centerOfMass = CM.localPosition;
        }
    }
コード例 #3
0
        public async Task <Differential> EditDifferential(Differential differential)
        {
            // fluent validation
            if (differential == null)
            {
                return(null);
            }
            else
            {
                var _differential = await _context.Differentials.FindAsync(differential.Id);

                _differential = differential;

                _context.Entry(_differential).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                await _context.SaveChangesAsync();

                return(differential);
            }
        }
コード例 #4
0
        public void Test()
        {
            Differential  d = new Differential();
            IOptiTestFunc f = new SumSquares();

            d.dimension   = 10;
            d.searchSpace = f.SearchSpace;
            double[] res = d.Opti(f.Func);
            double   val = f.Func(res);

            Assert.AreEqual(f.MinimumValue, val, 5);

            d             = new Differential();
            f             = new Weierstrass();
            d.dimension   = 10;
            d.searchSpace = f.SearchSpace;
            res           = d.Opti(f.Func);
            val           = f.Func(res);

            Assert.AreEqual(f.MinimumValue, val, 5);
        }
コード例 #5
0
ファイル: VolyExportsTests.cs プロジェクト: bloomtom/Volyar
        public void TestSerialization()
        {
            var deletion = new List <Deletion>()
            {
                new Deletion(TransactionTableType.MediaItem, 2)
            };
            var addition = new List <MediaItem>()
            {
                new MediaItem()
                {
                    LibraryName = "abc", MediaId = 3, Name = "123"
                }
            };
            var modification = new List <MediaItem>()
            {
                new MediaItem()
                {
                    LibraryName = "def", MediaId = 4, Name = "456"
                }
            };
            var diff = new Differential()
            {
                CurrentKey = 1, Deletions = deletion, Additions = addition, Modifications = modification
            };

            var a = JsonConvert.SerializeObject(deletion);
            var b = JsonConvert.DeserializeObject <IEnumerable <Deletion> >(a);

            var c = JsonConvert.SerializeObject(addition);
            var d = JsonConvert.DeserializeObject <IEnumerable <MediaItem> >(c);

            var r = JsonConvert.SerializeObject(diff);
            var s = JsonConvert.DeserializeObject <Differential>(r);

            Assert.AreEqual(1, s.CurrentKey);
            Assert.AreEqual(2, s.Deletions.First().Key);
            Assert.AreEqual(3, s.Additions.First().MediaId);
            Assert.AreEqual(4, s.Modifications.First().MediaId);
        }
コード例 #6
0
        public IRouteComponent Find(Differential differential, float distance)
        {
            if (source.attributes.length() > 4)
            {
                throw new IllegalRouteOperationException("Cannot use differential filter for data longer than 4 bytes");
            }

            if (source.attributes.length() <= 0)
            {
                throw new IllegalRouteOperationException("Cannot use differential filter for null data");
            }

            if (source.eventConfig[0] == (byte)SENSOR_FUSION)
            {
                throw new IllegalRouteOperationException("Cannot use differential filter on sensor fusion data");
            }

            var config = new DataProcessorConfig.DifferentialConfig(source.attributes, differential, (int)(distance * source.scale(state.bridge)));
            var next   = source.transform(config);

            return(postCreate(next.Item2, new DifferentialEditorInner(config, next.Item1, state.bridge)));
        }
コード例 #7
0
        static void Main(string[] args)
        {
            Differential alg = new Differential()
            {
                iterCount            = 5000,
                initialPopulation    = 1000,
                crossoverProbability = 0.5,
                differentialWeight   = 1.0,
                dimension            = 2,
                searchSpace          = new double[] { 0.0, 50.0 },
            };

            Console.WriteLine("Optimizing...");
            double[] result = alg.Opti(func);
            double   val    = -func(result); //multiply by -1 to get real value (see note in func)

            Console.WriteLine("Value: " + val + " at ");
            for (int i = 0; i < result.Length; i++)
            {
                Console.Write(result[i] + " ");
            }
        }
コード例 #8
0
        /// <summary>
        /// Convert between base 1024 storage units [TB, GB, MB, KB, Byte]
        /// </summary>
        /// <param name="SizeDifferential">Storage conversion differential [enum]</param>
        /// <param name="UnitSize">Size as mutiple of unit type units [double]</param>
        /// <param name="BaseUnit">Size of the base power [enum]</param>
        /// <returns>Converted unit size [double]</returns>
        public static double Convert(Differential SizeDifferential, double UnitSize, StorageBase BaseUnit = StorageBase.BASE10)
        {
            if (UnitSize < 0.000000000001)
            {
                return(0);
            }

            double POWER1 = 1000;
            double POWER2 = 1000000;
            double POWER3 = 1000000000;
            double POWER4 = 1000000000000;

            if (BaseUnit == StorageBase.BASE2)
            {
                POWER1 = 1024;
                POWER2 = 1048576;
                POWER3 = 1073741824;
                POWER4 = 1099511627776;
            }

            switch (SizeDifferential)
            {
            case Differential.ByteToKilo:
                return(UnitSize / POWER1);

            case Differential.ByteToMega:
                return(UnitSize / POWER2);

            case Differential.ByteToGiga:
                return(UnitSize / POWER3);

            case Differential.ByteToTera:
                return(UnitSize / POWER4);

            case Differential.KiloToByte:
                return(UnitSize * POWER1);

            case Differential.KiloToMega:
                return(UnitSize / POWER1);

            case Differential.KiloToGiga:
                return(UnitSize / POWER2);

            case Differential.KiloToTera:
                return(UnitSize / POWER3);

            case Differential.MegaToByte:
                return(UnitSize * POWER2);

            case Differential.MegaToKilo:
                return(UnitSize * POWER1);

            case Differential.MegaToGiga:
                return(UnitSize / POWER1);

            case Differential.MegaToTera:
                return(UnitSize / POWER2);

            case Differential.GigaToByte:
                return(UnitSize * POWER3);

            case Differential.GigaToKilo:
                return(UnitSize * POWER2);

            case Differential.GigaToMega:
                return(UnitSize * POWER1);

            case Differential.GigaToTerra:
                return(UnitSize / POWER1);

            case Differential.TeraToByte:
                return(UnitSize * POWER4);

            case Differential.TeraToKilo:
                return(UnitSize * POWER3);

            case Differential.TeraToMega:
                return(UnitSize * POWER2);

            case Differential.TeraToGiga:
                return(UnitSize * POWER1);
            }

            return(0);
        }
コード例 #9
0
 public SymbolData(Symbol symbol, Differential diff)
 {
     Symbol = symbol;
     DIFF   = diff;
     //State = State.Middle;
 }
コード例 #10
0
 private void Awake()
 {
     differential = GetComponent <Differential>();
     vehicleInput = GetComponent <VehicleInput>();
 }
コード例 #11
0
        public List <Differential> CountDifferentialsSingleSBox()
        {
            List <Differential> result     = new List <Differential>();
            Differential        diffToEdit = null;

            for (int i = 0; i < 16; i++)
            {
                for (int j = 0; j < 16; j++)
                {
                    int inputDiff  = i ^ j;
                    int outputDiff = ApplySingleSBox(i) ^ ApplySingleSBox(j);
                    //int outputDiff = ApplySBoxToBlock(i) ^ ApplySBoxToBlock(j);

                    if (inputDiff == 0 || outputDiff == 0)
                    {
                        continue;
                    }

                    bool found = false;

                    foreach (var curDiff in result)
                    {
                        if ((curDiff.InputDifferential == inputDiff) && (curDiff.OutputDifferential == outputDiff))
                        {
                            curDiff.Count++;
                            found      = true;
                            diffToEdit = curDiff;

                            break;
                        }
                    }

                    if (!found)
                    {
                        result.Add(new Differential()
                        {
                            Count              = 1,
                            InputDifferential  = inputDiff,
                            OutputDifferential = outputDiff,
                            InputPairList      = new List <Pair>()
                            {
                                new Pair()
                                {
                                    LeftMember = i, RightMember = j
                                }
                            },
                            OutputPairList = new List <Pair>()
                            {
                                new Pair()
                                {
                                    LeftMember = ApplySingleSBox(i), RightMember = ApplySingleSBox(j)
                                }
                                //new Pair(){LeftMember = ApplySBoxToBlock(i), RightMember = ApplySBoxToBlock(j)}
                            }
                        });
                    }
                    else
                    {
                        diffToEdit.InputPairList.Add(new Pair()
                        {
                            LeftMember = i, RightMember = j
                        });
                        diffToEdit.OutputPairList.Add(new Pair()
                        {
                            LeftMember = ApplySingleSBox(i), RightMember = ApplySingleSBox(j)
                        });
                        //diffToEdit.OutputPairList.Add(new Pair() { LeftMember = ApplySBoxToBlock(i), RightMember = ApplySBoxToBlock(j) });
                    }
                }
            }

            foreach (var curDiff in result)
            {
                curDiff.Probability = curDiff.Count / 16.0;
                //curDiff.Probability = curDiff.Count / 256.0;
            }

            result = result.OrderByDescending(item => item.Probability).ToList();
            return(result);
        }
コード例 #12
0
        private Characteristic FindBestCharacteristic(int round, List <Differential> differentialsList, int outputDiff, Characteristic res)
        {
            //end of rekursion
            if (round == 0)
            {
                return(res);
            }

            //contains the active SBoxes in the round
            bool[] activeSBoxes = new bool[CipherThreeConfiguration.SBOXNUM];

            //check active SBoxes
            int[] outputDiffs = new int[CipherThreeConfiguration.SBOXNUM];
            for (int i = 0; i < CipherThreeConfiguration.SBOXNUM; i++)
            {
                outputDiffs[i] = GetSubBlockFromBlock(outputDiff, i);
                if (outputDiffs[i] > 0)
                {
                    activeSBoxes[i] = true;
                }
                else
                {
                    activeSBoxes[i] = false;
                }
            }

            //resultList
            List <Characteristic> diffList = new List <Characteristic>();

            //prepare the arrayOfDifferentialLists
            List <Differential>[] arrayOfDifferentialLists = new List <Differential> [CipherThreeConfiguration.SBOXNUM];
            int comb = 1;

            for (int b = 0; b < CipherThreeConfiguration.SBOXNUM; b++)
            {
                if (activeSBoxes[b])
                {
                    arrayOfDifferentialLists[b] = new List <Differential>(differentialsList.Count);
                    differentialsList.ForEach((item) =>
                    {
                        arrayOfDifferentialLists[b].Add((Differential)item.Clone());
                    });

                    List <Differential> diffsToRemove = new List <Differential>();
                    for (int j = 0; j < arrayOfDifferentialLists[b].Count; j++)
                    {
                        if (arrayOfDifferentialLists[b][j].OutputDifferential != outputDiffs[b])
                        {
                            diffsToRemove.Add(arrayOfDifferentialLists[b][j]);
                        }
                    }

                    foreach (var curDiff in diffsToRemove)
                    {
                        arrayOfDifferentialLists[b].Remove(curDiff);
                    }

                    comb *= arrayOfDifferentialLists[b].Count;
                }
                else
                {
                    arrayOfDifferentialLists[b] = new List <Differential>();
                }
            }

            for (int c = 0; c < comb; c++)
            {
                Differential[] curDiffSBoxes = new Differential[CipherThreeConfiguration.SBOXNUM];

                //calc indices
                int indexNo = 0;
                int j       = c;
                while (j > 0)
                {
                    if (arrayOfDifferentialLists[indexNo].Count > 0)
                    {
                        int index = j % arrayOfDifferentialLists[indexNo].Count;
                        j = j / arrayOfDifferentialLists[indexNo].Count;
                        curDiffSBoxes[indexNo] = arrayOfDifferentialLists[indexNo][index];
                    }
                    indexNo++;
                }

                //zero case
                if (c == 0)
                {
                    for (int i = 0; i < CipherThreeConfiguration.SBOXNUM; i++)
                    {
                        if (activeSBoxes[i])
                        {
                            curDiffSBoxes[i] = arrayOfDifferentialLists[i][0];
                        }
                    }
                }

                //check null values
                for (int z = 0; z < CipherThreeConfiguration.SBOXNUM; z++)
                {
                    if (curDiffSBoxes[z] == null)
                    {
                        curDiffSBoxes[z] = new Differential()
                        {
                            Count              = 0,
                            InputDifferential  = 0,
                            OutputDifferential = 0,
                            Probability        = -1
                        };
                    }
                }

                //calc conditions
                bool satisfied = true;
                for (int i = 0; i < CipherThreeConfiguration.SBOXNUM; i++)
                {
                    if (curDiffSBoxes[i].OutputDifferential != outputDiffs[i])
                    {
                        satisfied = false;
                    }
                }

                //check if conditions are satisfied
                if (!satisfied)
                {
                    continue;
                }

                //copy object
                Characteristic characteristic = res.Clone() as Characteristic;

                //calculate inputDifference
                int inputDiff = 0;
                for (int i = CipherThreeConfiguration.SBOXNUM - 1; i >= 0; i--)
                {
                    inputDiff = inputDiff ^ curDiffSBoxes[i].InputDifferential;
                    if ((i - 1) >= 0)
                    {
                        inputDiff = inputDiff << CipherThreeConfiguration.BITWIDTHCIPHERFOUR;
                    }
                }

                //outputDifference for previous round
                int outputDiffPreviousRound = inputDiff;

                //calc new prob
                // ReSharper disable once CompareOfFloatsByEqualityOperator
                if (characteristic != null && characteristic.Probability != -1)
                {
                    for (int i = 0; i < CipherThreeConfiguration.SBOXNUM; i++)
                    {
                        if (curDiffSBoxes[i].Count == 0)
                        {
                            continue;
                        }
                        characteristic.Probability = characteristic.Probability * (curDiffSBoxes[i].Count / 16.0);
                    }
                }
                else
                {
                    double value = 1.0;
                    for (int i = 0; i < CipherThreeConfiguration.SBOXNUM; i++)
                    {
                        if (curDiffSBoxes[i].Count == 0)
                        {
                            continue;
                        }
                        value = value * (curDiffSBoxes[i].Count / 16.0);
                    }

                    if (characteristic != null)
                    {
                        characteristic.Probability = value;
                    }
                }

                //store result
                if (characteristic != null)
                {
                    characteristic.InputDifferentials[round - 1]  = inputDiff;
                    characteristic.OutputDifferentials[round - 1] = outputDiff;

                    //go one round deeper
                    Characteristic retval = FindBestCharacteristic(round - 1, differentialsList,
                                                                   outputDiffPreviousRound, characteristic);

                    //check if there is a result
                    if (retval != null)
                    {
                        diffList.Add(retval);
                    }
                }
            }

            //search for the best result
            Characteristic best = new CipherThreeCharacteristic();

            foreach (var curDiffs in diffList)
            {
                if (best.Probability < curDiffs.Probability)
                {
                    best = curDiffs;
                }
            }

            return(best);
        }