Beispiel #1
0
/* prints basic GUI that should always be visible */
void printGui(world* w) {
  wborder(w->Windows.Main, '*', '*', '*', '*', '*', '*', '*', '*'); 
  wborder(w->Windows.Status, '#', '#', '#', '#', '#', '#', '#', '#'); 

  printObjects(w);
  printPlayerStatus(w);
  printMap(w); 
}
Beispiel #2
0
int main()

{
	int num =20;
	srand(time(NULL));
	int knapSize=rand()%100;
 	object *items = createObjects(num);
	printf(" \n  KNAPSACK SIZE ::: %d ", knapSize);
	printObjects(items,num);
	int numEleminSack = 0 ; 
	object *result = getKnapSackObjects(items,num,knapSize,&numEleminSack);
	printResult(result,numEleminSack);
}	
Beispiel #3
0
object* getKnapSackObjects(object *inArray, int len, int knapSize, int *numReturn)
{
quickSort(inArray,0,len-1);
printObjects(inArray,len);

int i =0 ; 
object *resultArray = (object*)malloc(sizeof(object)*len);
int count = 0 ; 

for (i=0;i<len;i++)
	{
		if(knapSize==0)
			break;
		else
		{
			float PperW= (float)inArray[i].profit/inArray[i].weight;
			float wtUsed =0;
			if(inArray[i].weight<=knapSize)
				{
					wtUsed = inArray[i].weight;
				}
			else
				{
					//fractional
					wtUsed = knapSize ;		
				}

			resultArray[count].weight = wtUsed;
			resultArray[count].id  =  inArray[i].id;
			resultArray[count].profit = PperW*wtUsed;
			knapSize = knapSize - wtUsed;
			count++;
		}
	}
*numReturn =count;
return resultArray;

}
Beispiel #4
0
int main( void )
{

  // Create objects and give value to their propertiess
  TestObject obj1, obj2, obj3, obj4;

  obj1.attr1 = 3.4f;
  obj1.attr2 = 4;
  obj1.getProperty( "property3" ).set( 2.3f );
  obj1.getProperty( "property4" ).set( 4 );

  obj2.attr1 = 3.2f;
  obj2.attr2 = 10;
  obj2["property3"].set( 3.4f );
  obj2.getProperty( "property4" ).set( 10 );

  obj3.attr1 = 1.4f;
  obj3.attr2 = 3;
  obj3.getProperty( "property3" ).set( 4.5f );
  obj3.getProperty( "property4" ).set( 3 );

  obj4.attr1 = 4.1f;
  obj4.attr2 = 5;
  obj4.getProperty( "property3" ).set( 5.6f );
  obj4.getProperty( "property4" ).set( 5 );

  // Label objects
  obj1.label( ) = "Object 1";
  obj2.label( ) = "Object 2";
  obj3.label( ) = "Object 3";
  obj4.label( ) = "Object 4";

  fires::Objects objects;

  {
    objects.addList( { &obj1, &obj2, &obj3, &obj4 } );
    fires::FilterSet fs0;
    fires::FilterSetConfig fsc0;
    fires::FilterMinValue< float > ff10( 5.0f );

    fsc0.filters( ).push_back( std::make_pair( "property3", &ff10 ));
    fs0.eval( objects, fsc0 );
    printObjects( objects );
  }
  {
    objects.addList( { &obj1, &obj2, &obj3, &obj4 } );
    fires::FilterSet fs0;
    fires::FilterSetConfig fsc0;
    fires::FilterMaxValue< float > ff10( 5.0f );

    fsc0.filters( ).push_back( std::make_pair( "property3", &ff10 ));
    fs0.eval( objects, fsc0 );
    printObjects( objects );
  }

  objects.clearAdds( { &obj1, &obj2, &obj3, &obj4 } );

  fires::FilterSet fs;
  fires::FilterSetConfig fsc;
  fires::FilterScalarRange< float > ff1( 3.0f, 5.0f );
  fires::FilterScalarRange< int > fi1( 0, 9 );

  printObjects( objects );

  fsc.filters( ).push_back( std::make_pair( "property3", &ff1 ));
  fs.eval( objects, fsc );
  printObjects( objects );

  ff1.rangeInclusion( ) = fires::FilterRange::OUTSIDE_RANGE;
  fs.eval( objects, fsc );
  printObjects( objects );

  objects.clearAdds( { &obj1, &obj2, &obj3, &obj4 } );

  fsc.filters( ).push_back( std::make_pair( "property4", &fi1 ));
  fs.eval( objects, fsc );
  printObjects( objects );

  objects.clear( );
  objects.add( &obj1 );
  objects.add( &obj2 );
  objects.add( &obj3 );
  objects.add( &obj4 );

  ff1.rangeInclusion( ) = fires::FilterRange::INSIDE_RANGE;
  fsc.filterPropertyLabel( ) = std::string( "fires::filter" );
  fs.eval( objects, fsc );
  printObjects( objects, "fires::filter" );

  ff1.rangeInclusion( ) = fires::FilterRange::OUTSIDE_RANGE;
  fs.eval( objects, fsc );
  printObjects( objects, "fires::filter" );

}