we find some centers
This commit is contained in:
parent
af433e8a90
commit
0e734bd4e8
|
@ -25,6 +25,7 @@
|
|||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define BASE_H
|
||||
|
||||
|
|
|
@ -55,6 +55,9 @@ int main(int argc, char **argv)
|
|||
{
|
||||
printLog("Starting gem-graph-server...\n");
|
||||
|
||||
time_t t = time(&t);
|
||||
srand((unsigned) t);
|
||||
|
||||
//
|
||||
// Creating parameters structure for the Scheduler
|
||||
//
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "../include/localworker.h"
|
||||
|
||||
#include <sys/sysinfo.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static void *GreatScheduler(void *parameters);
|
||||
|
||||
|
@ -49,10 +48,8 @@ static inline void centerAssign(Center_t *center, int x, int y, int z)
|
|||
center->z = z;
|
||||
}
|
||||
|
||||
static inline Center_t *centerAdd(Center_t *anyCenter)
|
||||
static inline Center_t *centerAdd(Center_t *anyCenter, Center_t *newCenter)
|
||||
{
|
||||
Center_t *newCenter = (Center_t*) malloc(sizeof(Center_t));
|
||||
|
||||
Center_t *temp = anyCenter->next;
|
||||
anyCenter->next = newCenter;
|
||||
newCenter->next = temp;
|
||||
|
@ -76,6 +73,29 @@ static inline void centerRemove(Center_t *oldCenter)
|
|||
free(oldCenter);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
// Scheduler thread main function //
|
||||
// -------------------------------------------------------------------------- //
|
||||
static Center_t *findWorkArea(Center_t *centerList, int ruleRadius, size_t spaceSize)
|
||||
{
|
||||
Center_t *myCenter = (Center_t*) malloc(sizeof(Center_t));
|
||||
centerAssign(myCenter, rand() % spaceSize, 0, 0); /* Je suis né quelque part.(ou pas !).*/
|
||||
|
||||
while (centerList != NULL){
|
||||
//printLog("Center : %d\n", centerList->x);
|
||||
if (abs(myCenter->x - centerList->x) < ruleRadius){
|
||||
printLog("FAIL: no work area available at %d\n", myCenter->x);
|
||||
free(myCenter);
|
||||
return NULL;
|
||||
}
|
||||
centerList = centerList->next;
|
||||
}
|
||||
|
||||
printLog("SUCCESS ! at %d: < I've found a center.\n", myCenter->x);
|
||||
|
||||
return myCenter;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
// Scheduler thread main function //
|
||||
// -------------------------------------------------------------------------- //
|
||||
|
@ -93,29 +113,16 @@ static void *GreatScheduler(void *params)
|
|||
|
||||
centerAssign(centersList, -1, -1, -1);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
Center_t *workArea;
|
||||
int i = 0;
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
// Scheduler thread main function //
|
||||
// -------------------------------------------------------------------------- //
|
||||
static Center_t *findWorkArea(Center_t *centerList, int ruleRadius)
|
||||
{
|
||||
Center_t *myCenter = (Center_t*) malloc(sizeof(Center_t));
|
||||
centerAssign(myCenter, 10, 0, 0); /* Je suis né quelque part.(ou pas !).*/
|
||||
|
||||
while (centerList != NULL){
|
||||
if (abs(myCenter->x - centerList->x) < ruleRadius){
|
||||
printLog("FAIL: no work area available at %d\n", myCenter->x);
|
||||
free(myCenter);
|
||||
return NULL;
|
||||
while (1) {
|
||||
while ((workArea = findWorkArea(centersList, 4, 30))) {
|
||||
i++;
|
||||
centerAdd(centersList, workArea);
|
||||
}
|
||||
centerList = centerList->next;
|
||||
printLog("New centers : %d\n", i);
|
||||
}
|
||||
|
||||
printLog("SUCCESS ! at %d: < I've find a center.\n", myCenter->x);
|
||||
|
||||
return myCenter;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue