Exemple #1
0
        public void TryPlacePoint(bool isHydrophobic, Direction direction)
        {
            // Load lattice info
            LatticeInfo outputLattice = lattices[executionIndex];
            int         adjacentIndex = GetAdjacentIndex(outputLattice.lastIndex, direction);

            // Validate the placement is correct
            int originalPointIndex = baseIndex + adjacentIndex;

            if (points[originalPointIndex].index > 0)
            {
                outputLattices[executionIndex + (int)direction] = new LatticeInfo(false, 0, outputLattice.lastPoint + 1, adjacentIndex);
                return;
            }

            // Copy points to output
            CopyPoints(baseIndex, outputBaseIndex);

            // Place point
            int newPointIndex = outputBaseIndex + adjacentIndex;

            outputPoints[newPointIndex] = new Point()
            {
                index = ++outputLattice.lastPoint, isHydrophobic = isHydrophobic
            };

            // Update lattice info
            outputLattice.lastIndex = adjacentIndex;
            outputLattice.energy   += GetOutputEnergyPoint(outputBaseIndex + outputLattice.lastIndex, isHydrophobic);

            // Add new lattice info to output
            outputLattices[executionIndex * 4 + (int)direction] = outputLattice;
        }
        private void InitializeExecution()
        {
            // Create initial lattice
            latticeSize = 2 * parsedInput.Count + 2;

            points   = new NativeArray <Point>(latticeSize * latticeSize, Allocator.Persistent);
            lattices = new NativeArray <LatticeInfo>(1, Allocator.Persistent);

            // Place first two monomers arbitrarily
            int initialIndex = latticeSize * ((latticeSize - 1) / 2) + (latticeSize / 2);

            points[initialIndex]     = new Point(2, parsedInput[0]);
            points[initialIndex + 1] = new Point(3, parsedInput[1]);
            lattices[0] = new LatticeInfo(true, 0, 3, initialIndex + 1);
        }
        private void CreateOutputLattice()
        {
            LatticeInfo bestLatticeInfo = new LatticeInfo();
            int         bestIndex       = 0;

            for (int i = 0; i < lattices.Length; i++)
            {
                if (lattices[i].energy < bestLatticeInfo.energy)
                {
                    bestLatticeInfo = lattices[i];
                    bestIndex       = i;
                }
            }

            outputLattice.Value = new Lattice(
                points.GetSubArray(latticeSize * latticeSize

                                   * bestIndex, latticeSize * latticeSize).ToArray(),
                bestLatticeInfo.energy,
                latticeSize);

            points.Dispose();
            lattices.Dispose();
        }