用于强力变换长度数组的算法 [英] algorithm for brute force an variable lenght array
问题描述
您好,
我正试图找出另一种方法来强制使用不同可变长度内容的变量
长度向量。 />
int chromossome [MAX_VECTOR_LENGTH]
int max_value_for_each_chromossome [MAX_VALUES]
我所知道的唯一方法是建立''n' 'for(;;)语句,一个
在另一个内,但我需要1.000(MAX_VECTOR_LENGTH)
for(;;)inside for(;;)。
一个关键问题是每个染色体成员具有不同的max-
元素,例如:
chromossome [0]可能有max_value_for_each_chromossome [0] = 5
(chromossome [0] int的范围是0到4)
chromossome [1]可能有max_value_for_each_chromossome [1] = 2
(chromossome [1] int的范围从0到1)
....
是否有更简单的方法来实现这个而不是for(;;)里面
for(;;)scheme?
谢谢
Paulo
Hello,
I am trying to find out an alternate way to brute-force a variable
length vector with different variable length contents.
int chromossome[MAX_VECTOR_LENGTH]
int max_value_for_each_chromossome[MAX_VALUES]
The only way I am aware of is to build ''n'' for(;;) statements, one
inside the other, but I would then need 1.000 (MAX_VECTOR_LENGTH)
for(;;) inside for(;;).
One key issue is that each chromossome member has different max-
elements, for example:
chromossome[0] may have max_value_for_each_chromossome[0] = 5
(chromossome[0] int will range from 0 to 4)
chromossome[1] may have max_value_for_each_chromossome[1] = 2
(chromossome[1] int will range from 0 to 1)
....
Is there a simpler way to achive this rather than the for(;;) inside
for(;;) scheme?
Thank you
Paulo
推荐答案
es ****** @ gmail.com 写道:
您好,
我试图找出另一种方法来强制使用不同可变长度内容的变量
长度向量。
int chromossome [MAX_VECTOR_LENGTH]
int max_value_for_each_chromossome [MAX_VALUES]
我所知道的唯一方法是建立''n''对于(;;)语句,一个
在另一个内,但我需要1.000(MAX_VECTOR_LENGTH)
for(;;)inside for(;;)。 br />
一个关键问题是每个染色体成员具有不同的max-
元素,例如:
chromossome [ 0]可能有max_value_for_each_chromossome [0] = 5
(chromossome [0] int的范围从0到4)
chromossome [1]可能有max_value_for_eac h_chromossome [1] = 2
(chromossome [1] int的范围从0到1)
...
是否有更简单的方法来实现这个而不是(;;)里面的(;;)
for(;;)方案?
Hello,
I am trying to find out an alternate way to brute-force a variable
length vector with different variable length contents.
int chromossome[MAX_VECTOR_LENGTH]
int max_value_for_each_chromossome[MAX_VALUES]
The only way I am aware of is to build ''n'' for(;;) statements, one
inside the other, but I would then need 1.000 (MAX_VECTOR_LENGTH)
for(;;) inside for(;;).
One key issue is that each chromossome member has different max-
elements, for example:
chromossome[0] may have max_value_for_each_chromossome[0] = 5
(chromossome[0] int will range from 0 to 4)
chromossome[1] may have max_value_for_each_chromossome[1] = 2
(chromossome[1] int will range from 0 to 1)
...
Is there a simpler way to achive this rather than the for(;;) inside
for(;;) scheme?
我不明白你想要达到的目的。
-
pete
I don''t understand what you''re trying to achieve.
--
pete
5月17日,3:40 * pm,estan ... @ gmail.com写道:
On May 17, 3:40*pm, estan...@gmail.com wrote:
您好,
我试图找出一种替代方法来强制使用不同可变长度内容的变量
长度向量。
int chromossome [MAX_VECTOR_LENGTH]
int max_value_for_each_chromossome [MAX_VALUES]
Hello,
I am trying to find out an alternate way to brute-force a variable
length vector with different variable length contents.
int chromossome[MAX_VECTOR_LENGTH]
int max_value_for_each_chromossome[MAX_VALUES]
那么这些中的哪一个是可变长度的?或者你有一套
MAX_VECTOR_LENGTH数组,每个数组的长度设置为
max_value_each_chromossome []?
So which of these is variable length? Or do you have a set of
MAX_VECTOR_LENGTH arrays each of which has length set in
max_value_each_chromossome[]?
我所知道的唯一方法是为(;;)语句构建''n',在另一个内部构建一个
,但我需要1.000(MAX_VECTOR_LENGTH)
(;;)里面的(;;)
。
The only way I am aware of is to build ''n'' for(;;) statements, one
inside the other, but I would then need 1.000 (MAX_VECTOR_LENGTH)
for(;;) inside for(;;).
什么是n?我认为你不太可能需要for-loops
嵌套1000深。
What''s n? I would think it unlikely you will ever need for-loops
nested 1000-deep.
>
一个关键问题是每个染色体成员具有不同的max-
元素,例如:
chromossome [0]可能有max_value_for_each_chromossome [0] = 5
(chromossome [0] int的范围从0到4)
chromossome [1]可能有max_value_for_each_chromossome [1] = 2
(chromossome [1] int的范围从0到1)
>
One key issue is that each chromossome member has different max-
elements, for example:
chromossome[0] may have max_value_for_each_chromossome[0] = 5
(chromossome[0] int will range from 0 to 4)
chromossome[1] may have max_value_for_each_chromossome[1] = 2
(chromossome[1] int will range from 0 to 1)
所以[0]的范围是0..4。 [1]范围从0..1。似乎没有什么问题。
你想要实现的是什么?
或许可以使用小值给出一个更完整的例子
我们可以看到模式。
-
Bartc
So [0] ranges from 0..4. [1] ranges from 0..1. There doesn''t seem to
be a problem.
What is it you are trying to achieve?
Perhaps give a more fully worked out example using small values then
we can see the pattern.
--
Bartc
es ****** @ gmail.com 写道:
es******@gmail.com writes:
int chromossome [MAX_VECTOR_LENGTH]
int max_value_for_each_chromossome [MAX_VALUES]
我所知道的唯一方法是为(;;)语句构建''n',在另一个内部构建一个
,但我需要1.000(MAX_VECTOR_LENGTH)
$;
for(;;)inside for(;;)。
int chromossome[MAX_VECTOR_LENGTH]
int max_value_for_each_chromossome[MAX_VALUES]
The only way I am aware of is to build ''n'' for(;;) statements, one
inside the other, but I would then need 1.000 (MAX_VECTOR_LENGTH)
for(;;) inside for(;;).
我认为你试图迭代所有可能的价值
分配。我会做这样的事情(这是未经测试的):
for(i = 0; i< MAX_VECTOR_LENGTH; i ++)
chromossome [i ] = 0;
而(next_assignment(chromossome)){
..多东西..
}
>
/ *将chromossome中的值增加到下一个逻辑
值。如果成功则返回true,如果所有可能的
分配都已用尽则返回false。 * /
static int
next_assignment(int chromossome [MAX_VECTOR_LENGTH])
{
int i;
for(i = 0; i< MAX_VECTOR_LENGTH; i ++){
if(++ chromossome [i]< max_value_for_each_chromossome [i])
返回true;
chromossome [i] = 0;
}
返回false;
}
另外,你拼写错误的染色体。
-
char a [] =" \ n .CJacehknorstu" ; int putchar(int); int main(void){unsigned long b []
= {0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa6 7f6aaa,0xaa9aa9f6,0x11f6},* p
= b,i = 24; for(; p + =!* p; * p / = 4)switch(0 [p]& 3)case 0:{return 0; for(p - ; i - ; i - )case +
2:{i ++; if(i)break; else default:continue; if(0)case 1:putchar(a [i& 15]); break ;}}}
I think you''re trying to iterate through all possible value
assignments. I''d do something like this (which is untested):
for (i = 0; i < MAX_VECTOR_LENGTH; i++)
chromossome[i] = 0;
while (next_assignment(chromossome)) {
..do something..
}
/* Increments the values in chromossome to the next logical
value. Returns true if successful, false if all possible
assignments have been exhausted. */
static int
next_assignment(int chromossome[MAX_VECTOR_LENGTH])
{
int i;
for (i = 0; i < MAX_VECTOR_LENGTH; i++) {
if (++chromossome[i] < max_value_for_each_chromossome[i])
return true;
chromossome[i] = 0;
}
return false;
}
Also, you misspelled "chromosome".
--
char a[]="\n .CJacehknorstu";int putchar(int);int main(void){unsigned long b[]
={0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa6 7f6aaa,0xaa9aa9f6,0x11f6},*p
=b,i=24;for(;p+=!*p;*p/=4)switch(0[p]&3)case 0:{return 0;for(p--;i--;i--)case+
2:{i++;if(i)break;else default:continue;if(0)case 1:putchar(a[i&15]);break;}}}
这篇关于用于强力变换长度数组的算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!