public void AddShortage(Common.Resource r) { if (!shortages.Contains(r)) { shortages.Add(r); } }
public void ResolveShortage(Common.Resource r) { if (shortages.Contains(r)) { shortages.Remove(r); } }
public static Resource GetInstance(string ResouceName) { if (instance == null) { lock (_lock) { if (instance == null) { instance = new Resource(ResouceName); } } } return instance; }
public static Common.Resource CreateResourceRecord(string resourceName) { var info = TaskTimeMeter.GetClusterInfo(resourceName); var res = new Common.Resource(); res.Nodes = new Common.Node[info.NumberOfNodes]; res.Nodes = info.Node.Select(n => CreateNodeRecord(resourceName, n)).ToArray(); res.Parameters[NetworkDegradation.LCN] = info.LatencyClusterNode.ToString(); //res.LatencyPlannerCluster = info.LatencyPlannerCluster; res.Name = info.Name; /*res.ThroughputClusterNode = info.ThroughputClusterNode; * res.ThroughputPlannerCluster = info.ThroughputPlannerCluster;*/ return(res); }
public void SellFromCityInRange(Common.Resource resource, int quantity) { if (cityInRange == null) { throw new System.Exception("NO CITY IN RANGE"); } int cost = cityInRange.GetCost(resource) * quantity; if (stock[Common.ResId(resource)] < quantity) { throw new System.Exception("NOT ENOUGH RESOURCE"); } else { // OK gold += cost; cityInRange.AddResource(resource, quantity); stock[Common.ResId(resource)] -= quantity; } }
public void BuyFromCityInRange(Common.Resource resource, int quantity) { if (cityInRange == null) { throw new System.Exception("NO CITY IN RANGE"); } int cost = cityInRange.GetCost(resource) * quantity; if (gold < cost) { throw new System.Exception("NOT ENOUGH GOLD"); } else if (cityInRange.GetStock(resource) < quantity) { throw new System.Exception("NOT ENOUGH RESOURCE"); } else { // OK gold -= cost; cityInRange.AddResource(resource, -quantity); stock[Common.ResId(resource)] += quantity; } }
private void NewTradeBoat() { // New trade boat! Choose the destination city, using nearest first foreach (City c in citiesByNearest) { if (currentSpawnedBoats.Find(tb => tb.purpose.cityTarget == c)) { // already one going there continue; } // find a resource in the needs of this city and the production of here Common.Resource res = c.needs.Find(r => productions.Find(p => p.produces == r) != null); if (res != Common.Resource.NONE) { // A resource to deliver!! // need to create one boat! BoatNpc b = SpawnBoat(); // set its purpose b.purpose = new Purpose(Common.Purpose.TRADE, this, c, res); // DONE return; } } }
public virtual void AssignValues(Resource c, Map.Map map) { Name = c.Name; EditorPath = c.EditorPath; }
public static EstimationResult MeasureAppTime(string applicationId, IDictionary <string, string> parameters, Common.Resource resource, Common.LaunchDestination destination, bool optimize) { if (!AppDescriptions.ContainsKey(applicationId)) { throw new ApplicationNotFoundException(applicationId); } var app = new Application(AppDescriptions[applicationId], resource.Name); return(app.Estimate(parameters, resource, destination, optimize)); }
public string GetValue(Resource resource, LaunchDestination destination) { var nodes = resource.Nodes.Join(destination.NodeNames, n => n.DNSName, n => n, (n, name) => n).Distinct(); return Math.Floor((double)nodes.Sum(node => node.CoresTotal) / nodes.Count()).ToString(); }
public string GetValue(Resource resource, LaunchDestination destination) { return resource.Nodes.Join(destination.NodeNames, n => n.DNSName, n => n, (n, name) => n).Distinct().Count().ToString(); }
public static string GetValue(string parameterId, Resource resource, LaunchDestination destination) { if (resource == null || !ResourceParameterTypes.ContainsKey(parameterId)) { throw new HardwareParameterException(parameterId, resource == null ? null : resource.Name); } return ((IResourceHardwareParameter)ResourceParameterTypes[parameterId].GetConstructor(Type.EmptyTypes).Invoke(null)).GetValue(resource, destination); }
public string GetValue(Resource resource, LaunchDestination destination) { if (resource.Parameters.ContainsKey(Key)) { return resource.Parameters[Key]; } else { throw new HardwareParameterException(Id, resource.Name); } }
public string GetValue(Resource resource, LaunchDestination destination) { var nodes = resource.Nodes.Join(destination.NodeNames, n => n.DNSName, n => n, (n, name) => n).Distinct(); var cores = nodes.Select(n => Int32.Parse(ClusterParameterReader.GetValue(TotalNodeCores.TCORES, n), CultureInfo.InvariantCulture)).Sum(); var perf = nodes.Select(n => Double.Parse(ClusterParameterReader.GetValue(PERF, n), CultureInfo.InvariantCulture.NumberFormat)).Sum(); return (perf / cores).ToString(CultureInfo.InvariantCulture.NumberFormat); }
public virtual object Clone(Map.Map map) { Resource c = new Resource(); c.AssignValues(this, map); return c; }
public int GetStock(Common.Resource r) { return(stock[Common.ResId(r)]); }
internal void AddResource(Common.Resource resource, int v) { stock[Common.ResId(resource)] += v; }
public int GetCost(Common.Resource r) { return(Common.GetCostFromStock(stock[Common.ResId(r)])); }
internal int GetStock(Common.Resource resource) { return(stock[Common.ResId(resource)]); }
public static int ResId(Common.Resource r) { return(((int)r) - 1); }
public static Common.Resource CreateResourceRecord(string resourceName) { var info = TaskTimeMeter.GetClusterInfo(resourceName); var res = new Common.Resource(); res.Nodes = new Common.Node[info.NumberOfNodes]; res.Nodes = info.Node.Select(n => CreateNodeRecord(resourceName, n)).ToArray(); res.Parameters[NetworkDegradation.LCN] = info.LatencyClusterNode.ToString(); //res.LatencyPlannerCluster = info.LatencyPlannerCluster; res.Name = info.Name; /*res.ThroughputClusterNode = info.ThroughputClusterNode; res.ThroughputPlannerCluster = info.ThroughputPlannerCluster;*/ return res; }