| | | 1 | | using System.Collections; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Linq; |
| | | 4 | | using UnityEngine; |
| | | 5 | | |
| | | 6 | | // The clusterer class is an interface for clustering algorithms. |
| | | 7 | | public abstract class IClusterer { |
| | | 8 | | // List of game objects to cluster. |
| | | 9 | | protected List<GameObject> _objects = new List<GameObject>(); |
| | | 10 | | |
| | | 11 | | // List of clusters. |
| | | 12 | | protected List<Cluster> _clusters = new List<Cluster>(); |
| | | 13 | | |
| | | 14 | | public IClusterer(List<GameObject> objects) { |
| | | 15 | | _objects = objects; |
| | | 16 | | } |
| | | 17 | | public IClusterer(List<Agent> agents) { |
| | | 18 | | _objects = agents.ConvertAll(agent => agent.gameObject).ToList(); |
| | | 19 | | } |
| | | 20 | | |
| | | 21 | | // Get the list of game objects. |
| | | 22 | | public IReadOnlyList<GameObject> Objects { |
| | | 23 | | get { return _objects; } |
| | | 24 | | } |
| | | 25 | | |
| | | 26 | | // Get the list of clusters. |
| | | 27 | | public IReadOnlyList<Cluster> Clusters { |
| | | 28 | | get { return _clusters; } |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | // Cluster the game objects. |
| | | 32 | | public abstract void Cluster(); |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | // The size and radius-constrained clusterer class is an interface for clustering algorithms with |
| | | 36 | | // size and radius constraints. The size is defined as the maximum number of game objects within a |
| | | 37 | | // cluster, and the radius denotes the maximum distance from the cluster's centroid to any of its |
| | | 38 | | // assigned game objects. |
| | | 39 | | public abstract class ISizeAndRadiusConstrainedClusterer : IClusterer { |
| | | 40 | | // Maximum cluster size. |
| | 8 | 41 | | protected readonly int _maxSize = 0; |
| | | 42 | | |
| | | 43 | | // Maximum cluster radius. |
| | 8 | 44 | | protected readonly float _maxRadius = 0; |
| | | 45 | | |
| | | 46 | | public ISizeAndRadiusConstrainedClusterer(List<GameObject> objects, int maxSize, float maxRadius) |
| | 16 | 47 | | : base(objects) { |
| | 8 | 48 | | _maxSize = maxSize; |
| | 8 | 49 | | _maxRadius = maxRadius; |
| | 8 | 50 | | } |
| | | 51 | | public ISizeAndRadiusConstrainedClusterer(List<Agent> agents, int maxSize, float maxRadius) |
| | 0 | 52 | | : base(agents) { |
| | 0 | 53 | | _maxSize = maxSize; |
| | 0 | 54 | | _maxRadius = maxRadius; |
| | 0 | 55 | | } |
| | | 56 | | } |