Exemplo n.º 1
0
int main(int argc, char** argv) {

	FILE* fproblem = fopen(argv[1], "r");
	FILE* fsolution = fopen(argv[2], "r");

	if(fproblem == 0 || fsolution == 0) {
		printf("Error opening file\n");
		exit(1);
	}
	
	problem* prob = loadProblem(fproblem, fsolution);

	int* options = malloc(prob->size * sizeof(int));

	// Fill out the numbers which must appear in each house for this size
	for (int i = 1; i <= prob->size; ++i) {
		options[i - 1] = i;
	}

	if (!isValidSolution(prob, sqrt(prob->size), options)) errInvalidSol();
	else if (isComplete(prob)) printf("SOLVED\n");
	else printf("INCOMPLETE\n");
	
	freeProblem(prob);
}
Exemplo n.º 2
0
int main(int argc, const char * argv[]) {
    char load_input[300];
    int n_input;


printf("POOH");

    printf("load:");
    scanf("%s", load_input);

    printf("n:");
    scanf("%d", &n_input);

    loadProblem(load_input, n_input);



    printf("my name is RENZ");

    printf("my name is RENZ");

    printf("my name is NOTE");




    printf("my name is RENZ");
    printf("my name is NOTE");

    return 0;
}
Exemplo n.º 3
0
void
SolutionbasedShapeFunction :: computeDofTransformation(ActiveDof *dof, FloatArray &masterContribs)
{
    if ( !isLoaded ) {
        loadProblem();
    }

    FloatArray values, masterContribs2, d, values2;

    masterContribs.resize( this->giveDomain()->giveNumberOfSpatialDimensions() );
    masterContribs2.resize( this->giveDomain()->giveNumberOfSpatialDimensions() );

    IntArray dofIDs = {dof->giveDofID()};

    bool isPlus, isMinus, isZero, found;
    whichBoundary(* dof->giveDofManager()->giveCoordinates(), isPlus, isMinus, isZero);

    for ( int i = 1; i <= this->giveDomain()->giveNumberOfSpatialDimensions(); i++ ) {
        double factor = 1.0;
        found = false;

        modeStruct *ms = modes.at(i - 1);
        for ( size_t j = 0; j < ms->SurfaceData.size(); j++ ) {
            SurfaceDataStruct *sd = ms->SurfaceData.at(j);
            if ( sd->DofMan->giveNumber() == dof->giveDofManager()->giveNumber() ) {
                if ( sd->DofID == dof->giveDofID() ) {
                    values.resize(1);
                    values.at(1) = sd->value;
                    found = true;
                    break;
                }
            }
        }

        if ( !found ) {
            printf( "%u\n", dof->giveDofManager()->giveNumber() );
            OOFEM_ERROR("Node not found");
        }

        giveValueAtPoint(values2, * dof->giveDofManager()->giveCoordinates(), dofIDs, * modes.at(i - 1)->myEngngModel);

        //printf ("Mode %u, DofManager: %u, DofIDItem %u, value %10.10f\n", i, dof->giveDofManager()->giveNumber(), dof->giveDofID(), values.at(1));

        factor = isPlus  ? modes.at(i - 1)->ap : factor;
        factor = isMinus ? modes.at(i - 1)->am : factor;
        factor = isZero  ? 1.0 : factor;

        masterContribs.at(i) = factor * values2.at(1);
    }
}
Exemplo n.º 4
0
int 
OsiVolSolverInterface::readMps(const char *filename, const char *extension)
{
   CoinMpsIO reader;
   reader.setInfinity(getInfinity());
   int retVal = reader.readMps(filename, extension);
   loadProblem(*reader.getMatrixByCol(),
	       reader.getColLower(), reader.getColUpper(),
	       reader.getObjCoefficients(),
	       reader.getRowLower(), reader.getRowUpper());
   int nc = getNumCols();
   assert (continuous_);
   CoinFillN(continuous_, nc, true);
   return retVal;
}
Exemplo n.º 5
0
void HelloWorld::onKeyPress(EventKeyboard::KeyCode keyCode, Event *event)
{
	if (pushProblem)
	{
		auto prob = this->getChildByName("end");
		if (prob)
		{
			pushProblem = false;
			this->removeChild(prob);
		}
		return;
	}
	int px = 0, py = 0;
	switch (keyCode)
	{
	case EventKeyboard::KeyCode::KEY_UP_ARROW:
		break;
	case EventKeyboard::KeyCode::KEY_DOWN_ARROW:
		break;
	case EventKeyboard::KeyCode::KEY_LEFT_ARROW:
		px = -1;
		break;
	case EventKeyboard::KeyCode::KEY_RIGHT_ARROW:
		px = 1;
		break;
	case EventKeyboard::KeyCode::KEY_TAB:

		break;
	case EventKeyboard::KeyCode::KEY_SHIFT:

		break;
	case EventKeyboard::KeyCode::KEY_KP_ENTER:
		loadProblem(selectProblem);
		break;
	}
	probLabel[selectProblem]->setColor(Color3B::WHITE);
	selectProblem += px;
	if (selectProblem < 0) selectProblem = 0;
	else if (selectProblem >= nProblem) selectProblem = nProblem - 1;
	probLabel[selectProblem]->setColor(Color3B::RED);

}
Exemplo n.º 6
0
void
SolutionbasedShapeFunction :: computeBaseFunctionValueAt(FloatArray &answer, FloatArray &coords, IntArray &dofIDs, EngngModel &myEngngModel)
{
    answer.resize( dofIDs.giveSize() );
    answer.zero();

    if ( useConstantBase ) {
        for ( int i = 1; i <= answer.giveSize(); i++ ) {
            answer.at(i) = 1;
        }
        ;
    } else {
        std :: vector< FloatArray * >checkcoords;
        std :: vector< int >permuteIndex;
        int n = 0;

        if ( !isLoaded ) {
            loadProblem();
        }

        myEngngModel.giveDomain(1)->giveSpatialLocalizer()->init(false);

        if ( this->giveDomain()->giveNumberOfSpatialDimensions() == 2 ) {
            coords.resize(2);
        }

        // Determine if current coordinate is at a max or min point and if so, which type (on a surface, edge or a corner?)
        // n is the number of dimensions at which the point is an extremum, permuteIndex tells in which dimension the coordinate is max/min

        int thisMask = 0;

        for ( int i = 1; i <= coords.giveSize(); i++ ) {
            if ( ( fabs( maxCoord.at(i) - coords.at(i) ) < TOL ) || ( fabs( minCoord.at(i) - coords.at(i) ) < TOL ) ) {
                permuteIndex.push_back(i);
                n++;
                //thisMask = thisMask + pow(2.0, i - 1);   // compiler warning on conversion from double to int
                thisMask = thisMask + ( 0x01 << ( i - 1 ) );
            }
        }
        int _s = 0x01 << n;
        for ( int i = 0; i < _s; i++ ) {
            int mask = i, counter = 1;
            FloatArray *newCoord = new(FloatArray) ( coords.giveSize() );
            * newCoord = coords;

            for ( int j = 1; j <= n; j++ ) {
                double d = 0.0; //TOL;
                if ( ( mask & 1 ) == 0 ) { // Max
                    newCoord->at( permuteIndex.at(counter - 1) ) = minCoord.at( permuteIndex.at(counter - 1) ) + d;
                } else { // Min
                    newCoord->at( permuteIndex.at(counter - 1) ) = maxCoord.at( permuteIndex.at(counter - 1) ) - d;
                }
                counter++;
                mask = mask >> 1;
            }
            checkcoords.push_back(newCoord);
        }

        // The followind define allows for use of weakly periodic bc to be copied. This does not comply with the theory but is used to check the validity of the code.
#define USEWPBC 0

#if USEWPBC == 1
        FloatArray *tempCoord = new FloatArray;
        * tempCoord = coords;
        checkcoords.clear();
        checkcoords.push_back(tempCoord);
#endif
        FloatArray values;
        for ( size_t i = 0; i < checkcoords.size(); i++ ) {
            giveValueAtPoint(values, * checkcoords.at(i), dofIDs, myEngngModel);
            //printf("Values at (%f, %f, %f) are [%f, %f, %f]\n", checkcoords.at(i)->at(1), checkcoords.at(i)->at(2), checkcoords.at(i)->at(3), values.at(1), values.at(2), values.at(3));
#if USEWPBC == 1
            for ( int j = 1; j <= values.giveSize(); j++ ) {
                answer.at(j) = values.at(j);
            }
#else
            for ( int j = 1; j <= values.giveSize(); j++ ) {
                answer.at(j) = answer.at(j) + values.at(j) / ( ( double ) pow(2.0, n) );
            }
#endif
            delete( checkcoords.at(i) );
        }
    }
}