コード例 #1
0
//BRACMATDLL_API bool evaluate(const char * str,const char ** pout)
bool CBracmatdll::evaluate(const char * str,const char ** pout)
    {
    if(str)
        {
        const char * out;
        int err;
        stringEval(str,&out,&err);
        if(pout)
            *pout = out;
        return !err;
        }
    else
        return false;
    }
コード例 #2
0
int main(int argc,const char *argv[]){

	
	// set seed for random number generator
	unsigned int seed = (unsigned int)time(NULL);
	srand(seed);
	//printf("%d\n",seed);
	
	
	// what is the starting string
	char target[]="Target string";
	length = (int)strlen(target);  // use length of string function, cast it as an int because otherwise it's an unsigned int
		//strlen doesn't include the /0 in the length of the string
	
	//make a random starting sequence of letters
	char *startString = malloc((length+1)*sizeof(char));  /// BECAUSE strlen doesn't include the /0 in the length of the string
	int i;
	for(i=0; i < length; i++){
		startString[i]= randChar();
	}
	startString[length]='\0'; /// BECAUSE the array starts with a zero and goes to length (rather than length-1) then we just put the null character in there
	
	int muts = 0; //how many mutations happen to get to the target sequence
	int mutationsAtMismatches;
	
	while(stringEval(startString, target)>0){  // evolve the string of characters
		//mutate
		int site;
		do{
			site = rand_between(length);
			muts++;
		}while(startString[site]==target[site]);
		
		startString[site]=randChar();
		//evaluate how close the two strings are -- Hamming distance ( sum over units for if 1 when units are different and 0 if same )
			//--inherent in the loop
		//decide --inherent in the loop
		//stop when we get the phrase we want--inherent in the loop
		mutationsAtMismatches++;
		printf("%s \n", startString); //Print mutations to console as they happen
	}
	
printf("Number of mutations to target= %d \n", mutationsAtMismatches); //print the number of steps it takes to get to the target sequence
	
	
}
コード例 #3
0
ファイル: dk_cst_bracmat.c プロジェクト: BartJongejan/Bracmat
JNIEXPORT jstring JNICALL Java_dk_cst_bracmat_eval(JNIEnv * env, jobject obj, jstring expr)
    {
    int err;
    jstring ret;
    const char * str;
#if defined WIN32
    void mutexLockOut();
    void mutexUnlockOut();
    mutexLockOut();
#else
    pthread_mutex_lock( &mutexout);
#endif
    str = (*env)->GetStringUTFChars(env, expr, NULL);
    stringEval(str,&out,&err);
    ret = (*env)->NewStringUTF(env, out);
#if defined WIN32
    mutexUnlockOut();
#else
    pthread_mutex_unlock(&mutexout);
#endif
    return ret;
    }
コード例 #4
0
ファイル: dk_cst_bracmat.c プロジェクト: BartJongejan/Bracmat
JNIEXPORT jint JNICALL Java_dk_cst_bracmat_init(JNIEnv * env, jobject obj, jstring expr)
    {
    int err;
    jint ret;
#if defined WIN32
    void mutexLockInit();
    void mutexUnlockInit();
    mutexLockInit();
#else
    pthread_mutex_lock( &mutexinit);
#endif
    ret = startProc(0);
    if(ret == 1)
        {
        const char * str = (*env)->GetStringUTFChars(env, expr, NULL);
        stringEval((const char *)str,&out,&err); /*initialize, e.g. read program file*/
        }
#if defined WIN32
    mutexUnlockInit();
#else
    pthread_mutex_unlock(&mutexinit);
#endif
    return ret;
    }