Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 嗯,我忘了加那个了。虽然给定了一个时间跨度和动作数量,但这不只是cn的一次性添加吗?好吧,如果最大突发时间为m,从技术上讲,它将是m/action。每个动作的冷却时间分别为m/action。假设所有动作都有相等的冷却时间n,冷却时间应该是n*m/actio_Algorithm_Sorting_Optimization - Fatal编程技术网

Algorithm 嗯,我忘了加那个了。虽然给定了一个时间跨度和动作数量,但这不只是cn的一次性添加吗?好吧,如果最大突发时间为m,从技术上讲,它将是m/action。每个动作的冷却时间分别为m/action。假设所有动作都有相等的冷却时间n,冷却时间应该是n*m/actio

Algorithm 嗯,我忘了加那个了。虽然给定了一个时间跨度和动作数量,但这不只是cn的一次性添加吗?好吧,如果最大突发时间为m,从技术上讲,它将是m/action。每个动作的冷却时间分别为m/action。假设所有动作都有相等的冷却时间n,冷却时间应该是n*m/actio,algorithm,sorting,optimization,Algorithm,Sorting,Optimization,嗯,我忘了加那个了。虽然给定了一个时间跨度和动作数量,但这不只是cn的一次性添加吗?好吧,如果最大突发时间为m,从技术上讲,它将是m/action。每个动作的冷却时间分别为m/action。假设所有动作都有相等的冷却时间n,冷却时间应该是n*m/action.cooldown。是的,我认为我们与突发时间m和动作在同一页上。不必为集合中的每个动作重新计算冷却时间,因此,c=m/action.cooldown如果我们将其直接插入当前运行时间,我们将获得O((n*m/action.cooldown)l


嗯,我忘了加那个了。虽然给定了一个时间跨度和动作数量,但这不只是cn的一次性添加吗?好吧,如果最大突发时间为
m
,从技术上讲,它将是
m/action。每个动作的冷却时间分别为
m/action。假设所有动作都有相等的冷却时间
n
,冷却时间应该是
n*m/action.cooldown
。是的,我认为我们与突发时间
m
动作在同一页上。不必为集合中的每个动作重新计算冷却时间,因此,c=
m/action.cooldown
如果我们将其直接插入当前运行时间,我们将获得
O((n*m/action.cooldown)log(n*m/action.cooldown))
,它似乎没有任何明显的简化形式。这是我最初尝试的,但似乎最佳的解决方案是在较慢的冷却动作之间使用大量的快速冷却动作,这不会通过从高到低来实现;任何时候如果没有慢动作可用,你都会求助于快动作。如果高价值的行动足够慢,你会看到很多这样的快速行动;否则,你不会。当你有有限数量的不同行动可用时,在最坏的情况下做最好的,特别是当最好的有较长的冷却时间时,将导致你最终没有行动要做。以我在主帖子中的例子为例,如果你在前四秒钟内完成了DCBA,那么在5秒钟内你就没有什么事情可做了。我们的目标是能够每秒钟做一个动作,因此,像ABACABADABACB这样符合冷却要求的东西会更好。对不起,如果我解释我想要什么做得不好。哦,我终于明白了。我将使用Dijkstra算法解释一个解决方案,就好像这个问题是在地图上寻找可能最长的路线一样。查看我的编辑。。(完成后)我不完全理解为什么会返回最佳解决方案,但它似乎有效。明亮的
|---1---2---3---4---5---6---7---| time
|{--a1--}-----------------------| v=1
|---{--a2---}-------------------| v=1
|-------{--a3---}---------------| v=1
|{----b1----}-------------------| v=1.5
|---{----b2-----}---------------| v=1.5
|-------{----b3-----}-----------| v=1.5
|{--------c1--------}-----------| v=2
|---{--------c2---------}-------| v=2
|-------{-------c3----------}---| v=2
etc... 
Graph{//in most implementations these are not Arrays, but Maps. Honestly, for your needs you don't a graph, just nodes and arcs... this is just used to keep track of them.
node[] nodes;
arc[] arcs;
}
Node{//this represents an action
arc[] options;//for this implementation, this will always be a list of all possible Actions to use.
float value;//Action value
}
Arc{
node start;//the last action used
node end;//the action after that
dist=1;//1 second
}
A->na->A->na->A
B->na->na->B->na
A->B->A->na->B
B->A->na->B->A
...
    /*
     cur is the current action that you are at, it is a Node. In this example, every other action is seen as a viable option, so it's as if every 'place' on the map has a path going to every other path.
     numLeft is the amount of seconds left to run the simulation. The higher the initial value, the more desirable the results.

This won't work as written, but will give you a good idea of how the algorithm works.
*/
function getOptimal(cur,numLeft,path){
  if(numLeft==0){
    var emptyNode;//let's say, an empty node wiht a value of 0.
    return emptyNode;
  }
  var best=path;
  path.add(cur);
  for(var i=0;i<cur.options.length;i++){
    var opt=cur.options[i];//this is a COPY
    if(opt.timeCooled<opt.cooldown){
      continue;
    }
    for(var i2=0;i2<opt.length;i2++){
      opt[i2].timeCooled+=1;//everything below this in the loop is as if it is one second ahead
    }
    var potential=getOptimal(opt[i],numLeft-1,best);
    if(getTotal(potential)>getTotal(cur)){best.add(potential);}//if it makes it better, use it! getTotal will sum up the values of an array of nodes(actions)
  }
  return best;
}
function getOptimalExample(){
  log(getOptimal(someNode,4,someEmptyArrayOfNodes));//someNode will be A or B
}
function getOptimal(){
var a=[A,B,C,D];//A,B,C, and D are actions
a.sort()//(just pseudocode. Sort the array items by how much value they have.)
var theBest=null;
for(var i=0;i<a.length;++i){//find which action is the most valuable
     if(a[i].timeSinceLastUsed<a[i].cooldown){
        theBest=a[i];
        for(...){//now just loop through, and add time to each OTHER Action for their timeSinceLastUsed...
             //...
         }//That way, some previously used, but more valuable actions will be freed up again.
        break;
    }//because a is worth the most, and you can use it now, so why not?
}
}