Пример #1
0
int Filesys::fssynch() {
    // Write FAT to Sdisk.
    std::string buffer;
    std::ostringstream outstream, outstream2;
    for (int i = 0; i < getNumberOfBlocks(); i++) {
        outstream << std::setfill('0') << std::setw(5)<< fat[i] << " ";
    }
    buffer = outstream.str();
    // Block before writing
    std::vector<std::string> blocks = block(buffer, getBlocksize());
    //std::cout << "blocks size: " << blocks.size() << '\n';
    for (int i = 1; i <= blocks.size(); i++) {
        //std::cout << blocks[i-1] << '\n';
        putBlock(i, blocks[i - 1]);
    }

    // Now write root to disk
    for (int i = 0; i < rootSize; i++) {
        outstream2 << fileName[i] << " " << std::setfill('0') 
                   << std::setw(5) << firstBlock[i] << " ";
    }
    buffer = outstream2.str();
    //std::cout << "Root buffer: " << buffer << '\n';
    blocks.clear();
    blocks = block(buffer, getBlocksize());
    //std::cout << "blocks size: " << blocks.size() << '\n';
    for (int i = 0; i < blocks.size(); i++) {
        putBlock(i, blocks[i]);
    }
}
Пример #2
0
	int main(){
		if ((blocks = getNumberOfBlocks()) == 0) return 0;
		initializeWorld();
		int params_read, a, b;
		char cmd[4], cmd2[4];
		int initial_r,initial_c;
		while ((params_read = scanf("%s %d %s %d\n",cmd,&a,cmd2,&b)) > 0){
			if (params_read == 1 && strcmp(cmd,"quit")) break;
			else if (a != b && !inSameStack(a,b)){ 
				int command = getCommand(cmd,cmd2);
				switch (command){
					case MOVE_ONTO:
						find(b,&initial_r,&initial_c);
						if (returnBlocks(a) != 0) return 1;
						if (returnBlocks(b) != 0) return 2;
						if (move(a,b,initial_r,initial_c) != 0) return 3;
						break;
					case MOVE_OVER:
						find(b,&initial_r,&initial_c);
						if (returnBlocks(a) != 0) return 1;
						if (move(a,b,initial_r,initial_c) != 0) return 3;
						break;
					case PILE_ONTO:
						find(b,&initial_r,&initial_c);
						if (returnBlocks(b) != 0) return 1;
						if (move(a,b,initial_r,initial_c) != 0) return 3;
						break;
					case PILE_OVER:
						find(b,&initial_r,&initial_c);
						if (move(a,b,initial_r,initial_c) != 0) return 3;
						break;
					default:
						break;
				}
			}
		}
		printWorld();
		return 0;
	}
Пример #3
0
returnValue Constraint::getForwardSensitivities( BlockMatrix &D, int order ) {

    const int N = grid.getNumPoints();

    returnValue returnvalue;
    BlockMatrix result;

    result.init( getNumberOfBlocks(), 5*N );

    int nc, run1, run2;
    nc = 0;

    // BOUNDARY CONSTRAINTS:
    // ---------------------

    if( boundary_constraint->getNC() != 0 ) {
        BlockMatrix res;
        returnvalue = boundary_constraint->getForwardSensitivities( &res, order );
        if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue);
        Matrix res_;
        for( run2 = 0; run2 < 5*N; run2++ ) {
            res.getSubBlock( 0 , run2, res_ );
            if( res_.getDim() > 0 )
                result.setDense( nc, run2, res_ );
        }
        nc++;
    }

    // COUPLED PATH CONSTRAINTS:
    // -------------------------

    if( coupled_path_constraint->getNC() != 0 ) {
        BlockMatrix res;
        returnvalue = coupled_path_constraint->getForwardSensitivities( &res, order );
        if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue);
        Matrix res_;
        for( run2 = 0; run2 < 5*N; run2++ ) {
            res.getSubBlock( 0 , run2, res_ );
            if( res_.getDim() > 0 )
                result.setDense( nc, run2, res_ );
        }
        nc++;
    }


    // PATH CONSTRAINTS:
    // -----------------

    if( path_constraint->getNC() != 0 ) {
        BlockMatrix res;
        returnvalue = path_constraint->getForwardSensitivities( &res, order );
        if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue);
        Matrix res_;
        for( run1 = 0; run1 < N; run1++ ) {
            for( run2 = 0; run2 < 5*N; run2++ ) {
                res.getSubBlock( run1, run2, res_ );
                if( res_.getDim() > 0 )
                    result.setDense( nc  , run2, res_ );
            }
            nc++;
        }
    }


    // ALGEBRAIC CONSISTENCY CONSTRAINTS:
    // ----------------------------------

    if( algebraic_consistency_constraint->getNC() != 0 ) {
        BlockMatrix res;
        returnvalue = algebraic_consistency_constraint->getForwardSensitivities( &res, order );
        if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue);
        Matrix res_;
        for( run1 = 0; run1 < N; run1++ ) {
            for( run2 = 0; run2 < 5*N; run2++ ) {
                res.getSubBlock( run1, run2, res_ );
                if( res_.getDim() > 0 )
                    result.setDense( nc  , run2, res_ );
            }
            nc++;
        }
    }



    // POINT CONSTRAINTS:
    // ------------------

    if( point_constraints != 0 ) {
        for( run1 = 0; run1 < (int) grid.getNumPoints(); run1++ ) {
            if( point_constraints[run1] != 0 ) {
                BlockMatrix res;
                returnvalue = point_constraints[run1]->getForwardSensitivities( &res, order );
                if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue);
                Matrix res_;
                for( run2 = 0; run2 < 5*N; run2++ ) {
                    res.getSubBlock( 0 , run2, res_ );
                    if( res_.getDim() > 0 )
                        result.setDense( nc, run2, res_ );
                }
                nc++;
            }
        }
    }

    D = result;

    return SUCCESSFUL_RETURN;
}
Пример #4
0
returnValue Constraint::getConstraintResiduum( BlockMatrix &lowerRes, BlockMatrix &upperRes ) {

    const int N = grid.getNumPoints();

    returnValue returnvalue;

    BlockMatrix residuumL;
    BlockMatrix residuumU;

    residuumL.init( getNumberOfBlocks(), 1 );
    residuumU.init( getNumberOfBlocks(), 1 );

    int nc, run1;

    nc = 0;

    // BOUNDARY CONSTRAINTS:
    // ---------------------

    if( boundary_constraint->getNC() != 0 ) {
        BlockMatrix resL, resU;
        returnvalue = boundary_constraint->getResiduum( resL, resU );
        if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue);
        Matrix resL_;
        Matrix resU_;
        resL.getSubBlock( 0, 0, resL_ );
        resU.getSubBlock( 0, 0, resU_ );
        residuumL.setDense( nc, 0, resL_ );
        residuumU.setDense( nc, 0, resU_ );
        nc++;
    }


    // COUPLED PATH CONSTRAINTS:
    // -------------------------

    if( coupled_path_constraint->getNC() != 0 ) {
        BlockMatrix resL, resU;
        returnvalue = coupled_path_constraint->getResiduum( resL, resU );
        if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue);
        Matrix resL_;
        Matrix resU_;
        resL.getSubBlock( 0, 0, resL_ );
        resU.getSubBlock( 0, 0, resU_ );
        residuumL.setDense( nc, 0, resL_ );
        residuumU.setDense( nc, 0, resU_ );
        nc++;
    }


    // PATH CONSTRAINTS:
    // -----------------

    if( path_constraint->getNC() != 0 ) {
        BlockMatrix resL, resU;
        returnvalue = path_constraint->getResiduum( resL, resU );
        if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue);
        Matrix resL_;
        Matrix resU_;
        for( run1 = 0; run1 < N; run1++ ) {
            resL.getSubBlock( run1, 0, resL_ );
            resU.getSubBlock( run1, 0, resU_ );
            residuumL.setDense( nc, 0, resL_ );
            residuumU.setDense( nc, 0, resU_ );
            nc++;
        }
    }

    // ALGEBRAIC CONSISTENCY CONSTRAINTS:
    // ----------------------------------

    if( algebraic_consistency_constraint->getNC() != 0 ) {
        BlockMatrix resL, resU;
        returnvalue = algebraic_consistency_constraint->getResiduum( resL, resU );
        if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue);
        Matrix resL_;
        Matrix resU_;
        for( run1 = 0; run1 < N; run1++ ) {
            resL.getSubBlock( run1, 0, resL_ );
            resU.getSubBlock( run1, 0, resU_ );
            residuumL.setDense( nc, 0, resL_ );
            residuumU.setDense( nc, 0, resU_ );
            nc++;
        }
    }

    // POINT CONSTRAINTS:
    // ------------------

    if( point_constraints != 0 ) {
        for( run1 = 0; run1 < (int) grid.getNumPoints(); run1++ ) {
            if( point_constraints[run1] != 0 ) {
                BlockMatrix resL, resU;
                returnvalue = point_constraints[run1]->getResiduum( resL, resU );
                if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue);
                Matrix resL_;
                Matrix resU_;
                resL.getSubBlock( 0, 0, resL_ );
                resU.getSubBlock( 0, 0, resU_ );
                residuumL.setDense( nc, 0, resL_ );
                residuumU.setDense( nc, 0, resU_ );
                nc++;
            }
        }
    }

    lowerRes = residuumL;
    upperRes = residuumU;

    return SUCCESSFUL_RETURN;
}