25.04.2006, 11:08
Nach langem probieren, habe ich es nun endlich geschafft einen Array of Cluster einzulesen und einen größeren auszugeben, leider ist der code noch sehr langsam. Vielleicht hat ja jemand eine Idee wie man den Code verbessern könnte und das häßliche Vorcodieren der DLL verhindern kann.
Grüße Hepman
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "extcode.h"
# include <math.h>
/* LabVIEW created typdefs */
typedef struct {
int32 dimSize;
float64 Numeric[1];
} TD3;
typedef TD3 **TD3Hdl;
typedef struct {
double fitness;
TD3Hdl Array;
} TD2;
typedef struct {
long dimSize;
TD2 arg[1];
} TD4;
typedef TD4 **TD4Hdl;
extern "C" void __declspec(dllexport) Roulette_fast(TD4Hdl input, TD4Hdl output);
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
double Round(double Zahl, int Stellen)
{
return floor(Zahl * pow( 10, Stellen) + 0.5) * pow(10, -Stellen);
}
void __declspec(dllexport) Roulette_fast(TD4Hdl input, TD4Hdl output)
{
double Sum=0, InvSum=0;
unsigned int offset=0;
//(*output)->dimSize=100;
unsigned int size=(*input)->dimSize;
unsigned int undersize=(*((*input)->arg->Array))->dimSize;
(*((*output)->arg->Array))->dimSize=(*((*input)->arg->Array))->dimSize;
for(unsigned int i = 0; i < size ; i++)
{
Sum+=((*input)->arg[i].fitness);
InvSum+=1/((*input)->arg[i].fitness);
}
for(i = 0; i < size ; i++)
{
unsigned int run=(unsigned int)(Round((((*input)->arg[i].fitness)/Sum)*100,0));
for(unsigned int k=offset;k<(offset+run);k++)
{
(*output)->arg[k].fitness=(*input)->arg[i].fitness;
for(unsigned int m=0;m<undersize;m++)
{
(*(*output)->arg[k].Array)->Numeric[m]=(*(*input)->arg[i].Array)->Numeric[m];
}
}
offset=offset+run;
}
}
Grüße Hepman
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "extcode.h"
# include <math.h>
/* LabVIEW created typdefs */
typedef struct {
int32 dimSize;
float64 Numeric[1];
} TD3;
typedef TD3 **TD3Hdl;
typedef struct {
double fitness;
TD3Hdl Array;
} TD2;
typedef struct {
long dimSize;
TD2 arg[1];
} TD4;
typedef TD4 **TD4Hdl;
extern "C" void __declspec(dllexport) Roulette_fast(TD4Hdl input, TD4Hdl output);
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
double Round(double Zahl, int Stellen)
{
return floor(Zahl * pow( 10, Stellen) + 0.5) * pow(10, -Stellen);
}
void __declspec(dllexport) Roulette_fast(TD4Hdl input, TD4Hdl output)
{
double Sum=0, InvSum=0;
unsigned int offset=0;
//(*output)->dimSize=100;
unsigned int size=(*input)->dimSize;
unsigned int undersize=(*((*input)->arg->Array))->dimSize;
(*((*output)->arg->Array))->dimSize=(*((*input)->arg->Array))->dimSize;
for(unsigned int i = 0; i < size ; i++)
{
Sum+=((*input)->arg[i].fitness);
InvSum+=1/((*input)->arg[i].fitness);
}
for(i = 0; i < size ; i++)
{
unsigned int run=(unsigned int)(Round((((*input)->arg[i].fitness)/Sum)*100,0));
for(unsigned int k=offset;k<(offset+run);k++)
{
(*output)->arg[k].fitness=(*input)->arg[i].fitness;
for(unsigned int m=0;m<undersize;m++)
{
(*(*output)->arg[k].Array)->Numeric[m]=(*(*input)->arg[i].Array)->Numeric[m];
}
}
offset=offset+run;
}
}