예제 #1
0
 public void AddShortage(Common.Resource r)
 {
     if (!shortages.Contains(r))
     {
         shortages.Add(r);
     }
 }
예제 #2
0
 public void ResolveShortage(Common.Resource r)
 {
     if (shortages.Contains(r))
     {
         shortages.Remove(r);
     }
 }
예제 #3
0
 public static Resource GetInstance(string ResouceName)
 {
     if (instance == null)
     {
         lock (_lock)
         {
             if (instance == null)
             {
                 instance = new Resource(ResouceName);
             }
         }
     }
     return instance;
 }
예제 #4
0
        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);
        }
예제 #5
0
    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;
        }
    }
예제 #6
0
    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;
        }
    }
예제 #7
0
 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;
         }
     }
 }
예제 #8
0
 public virtual void AssignValues(Resource c, Map.Map map)
 {
     Name = c.Name;
     EditorPath = c.EditorPath;
 }
예제 #9
0
        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));
        }
예제 #10
0
 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();
 }
예제 #11
0
 public string GetValue(Resource resource, LaunchDestination destination)
 {
     return resource.Nodes.Join(destination.NodeNames, n => n.DNSName, n => n, (n, name) => n).Distinct().Count().ToString();
 }
예제 #12
0
        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);
        }
예제 #13
0
 public string GetValue(Resource resource, LaunchDestination destination)
 {
     if (resource.Parameters.ContainsKey(Key))
     {
         return resource.Parameters[Key];
     }
     else
     {
         throw new HardwareParameterException(Id, resource.Name);
     }
 }
예제 #14
0
 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);
 }
예제 #15
0
 public virtual object Clone(Map.Map map)
 {
     Resource c = new Resource();
     c.AssignValues(this, map);
     return c;
 }
예제 #16
0
 public int GetStock(Common.Resource r)
 {
     return(stock[Common.ResId(r)]);
 }
예제 #17
0
 internal void AddResource(Common.Resource resource, int v)
 {
     stock[Common.ResId(resource)] += v;
 }
예제 #18
0
 public int GetCost(Common.Resource r)
 {
     return(Common.GetCostFromStock(stock[Common.ResId(r)]));
 }
예제 #19
0
 internal int GetStock(Common.Resource resource)
 {
     return(stock[Common.ResId(resource)]);
 }
예제 #20
0
 public static int ResId(Common.Resource r)
 {
     return(((int)r) - 1);
 }
예제 #21
0
 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;
 }