コード例 #1
0
ファイル: mds.c プロジェクト: AlessandroBeggiato/MultiUbic
/*
 * ALESSANDRO: this is computed in the dumbest possible way
 */
void applyTransitiveClosure(){
	int i,j,k;
	for(i = 0; i < policy->levelNumber; ++i){
		for(j = 0; j < policy->levelNumber; ++j)
			for(k = 0; k < policy->levelNumber; ++k)
				if(FLOW(i,j)&&FLOW(j,k))FLOW(i,k)=1;
	}
}
コード例 #2
0
	FLOW maxFlow(int s, int t) {
		FLOW f = FLOW();
		
		while (1) {
			bfs(s);
			
			if (level[t] < 0) return f;
			
			fill(allof(iter), 0);
			FLOW fl;
			while ((fl = dfs(s, t, FLOW(iINF))) > 0) f += fl;
		}
	}
コード例 #3
0
ファイル: mds.c プロジェクト: AlessandroBeggiato/MultiUbic
void initializeMDS(int levels){
	//printf("Initialize MDS with %d levels\n", levels);
	int i,j;
	policy = malloc(sizeof(struct mds));
	policy->isTransitive=0;
	policy->levelNumber=levels;
	policy->levelNames = malloc(levels * sizeof(char*));
	policy->flow = malloc(levels * levels * sizeof(int));
	for(i = 0; i < levels; ++i){
		policy->levelNames[i] = NULL;
		for(j=0; j < levels; ++j)
			if(i==j)FLOW(i,j) = 1;
			else FLOW(i,j) = 0;
	}
}
コード例 #4
0
ファイル: ahci_port.cpp プロジェクト: ErfanBagheri/haiku
status_t
AHCIPort::FillPrdTable(volatile prd *prdTable, int *prdCount, int prdMax,
                       const physical_entry *sgTable, int sgCount, size_t dataSize)
{
    *prdCount = 0;
    while (sgCount > 0 && dataSize > 0) {
        size_t size = min_c(sgTable->size, dataSize);
        phys_addr_t address = sgTable->address;
        T_PORT(AHCIPortPrdTable(fController, fIndex, address, size));
        FLOW("FillPrdTable: sg-entry addr %#" B_PRIxPHYSADDR ", size %lu\n",
             address, size);
        if (address & 1) {
            TRACE("AHCIPort::FillPrdTable: data alignment error\n");
            return B_ERROR;
        }
        dataSize -= size;
        while (size > 0) {
            size_t bytes = min_c(size, PRD_MAX_DATA_LENGTH);
            if (*prdCount == prdMax) {
                TRACE("AHCIPort::FillPrdTable: prd table exhausted\n");
                return B_ERROR;
            }
            FLOW("FillPrdTable: prd-entry %u, addr %p, size %lu\n",
                 *prdCount, address, bytes);

            prdTable->dba = LO32(address);
            prdTable->dbau = HI32(address);
            prdTable->res = 0;
            prdTable->dbc = bytes - 1;
            *prdCount += 1;
            prdTable++;
            address = address + bytes;
            size -= bytes;
        }
        sgTable++;
        sgCount--;
    }
    if (*prdCount == 0) {
        TRACE("AHCIPort::FillPrdTable: count is 0\n");
        return B_ERROR;
    }
    if (dataSize > 0) {
        TRACE("AHCIPort::FillPrdTable: sg table %ld bytes too small\n",
              dataSize);
        return B_ERROR;
    }
    return B_OK;
}
コード例 #5
0
ファイル: ahci_sim.cpp プロジェクト: AmirAbrams/haiku
//! execute request
static void
ahci_scsi_io(scsi_sim_cookie cookie, scsi_ccb *request)
{
	FLOW("ahci_scsi_io, cookie %p, path_id %u, target_id %u, target_lun %u\n",
		cookie, request->path_id, request->target_id, request->target_lun);
	static_cast<AHCIController *>(cookie)->ExecuteRequest(request);
}
コード例 #6
0
ファイル: mds.c プロジェクト: AlessandroBeggiato/MultiUbic
void debugMDS(){
	printf(policy->isTransitive?"Transitive":"Intransitive");
	printf(" policy:\n");
	int i, j;
	for(i=0; i < policy->levelNumber;++i)
		for(j=0; j < policy->levelNumber;++j)
			printf(FLOW(i,j)?"%s->%s\n":"",policy->levelNames[i],policy->levelNames[j]);
}
コード例 #7
0
ファイル: ant.c プロジェクト: gpolo/QAP
int symmetric_calc_reduction(QAP_t *prob, QAP_solution_t *sol, int r, int s){
    int k;
    int reduction = 0;
    for (k = 0; k < prob->size; k++){
         if (k == r || k == s) continue;   
         reduction += (prob->dist[k][r] - prob->dist[k][s]) * (FLOW(prob, sol, k, s) - FLOW(prob, sol, k, r));

    }
    return reduction * 2;
}
コード例 #8
0
void GPSDATA::PASER_GPS::startGPS() {
    if(conf.GPS_ENABLE == 0){
        return;
    }
    bool error;
    bool m_ReadingStarted = false;
    // repeating reconnection if problems arise
    do {
        error = false;
        try {
            // create the serial device, note it takes the io service and the port name
            m_Port = new serial_port(m_IO, conf.GPS_SERIAL_PORT);
//            m_Port = new serial_port(m_IO, "/dev/ttyS2");
        } catch (...) {
            error = true;
            PASER_LOG_WRITE_LOG(PASER_LOG_ERROR, "Problem wile trying to access port %s\n", conf.GPS_SERIAL_PORT.c_str());
            boost::xtime xt;
            boost::xtime_get(&xt, boost::TIME_UTC);

            xt.nsec += 1000000000;
            boost::thread::sleep(xt);
            // after some time try to reconnect;
        }
    } while (error);

    // prepare settings
    serial_port_base::baud_rate BAUD(conf.GPS_SERIAL_SPEED); // what baud rate do we communicate at
//    serial_port_base::baud_rate BAUD(4800); // what baud rate do we communicate at
    serial_port_base::character_size CSIZE2(8); // how big is each "packet" of data (default is 8 bits)
    serial_port_base::flow_control FLOW(serial_port_base::flow_control::none); // what flow control is used (default is none)
    serial_port_base::parity PARITY(serial_port_base::parity::none); // what parity is used (default is none)
    serial_port_base::stop_bits STOP(serial_port_base::stop_bits::one); // how many stop bits are used (default is one)

    // go through and set all the options as we need them
    // all of them are listed, but the default values work for most cases
    m_Port->set_option(BAUD);
    m_Port->set_option(CSIZE2);
    m_Port->set_option(FLOW);
    m_Port->set_option(PARITY);
    m_Port->set_option(STOP);

    if (!m_ReadingStarted) {
        boost::thread t(boost::bind(&boost::asio::io_service::run, &m_IO));
        boost::asio::async_read_until(*m_Port, b, '\n',
                boost::bind(&GPSDATA::PASER_GPS::Handler, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
        m_ReadingStarted = true;
    }

}
コード例 #9
0
	FLOW dfs(int v, int t, FLOW f) {
		if (v == t) return f;
		
		int edge_nums = size_of(edges[v]);
		for (int& i = iter[v]; i < edge_nums; ++i) {
			Edge& e = edges[v][i];
			
			if (e.cost > 0 && level[v] < level[e.to]) {
				FLOW d = dfs(e.to, t, min(f, e.cost));
				if (d > 0) {
					e.cost -= d;
					edges[e.to][e.rev].cost += d;
					return d;
				}
			}
		}
		
		return FLOW(-1);
	}
コード例 #10
0
ファイル: ahci_port.cpp プロジェクト: ErfanBagheri/haiku
void
AHCIPort::ExecuteSataRequest(sata_request *request, bool isWrite)
{
    FLOW("ExecuteAtaRequest port %d\n", fIndex);

    StartTransfer();

    int prdEntrys;

    if (request->ccb() && request->ccb()->data_length) {
        FillPrdTable(fPRDTable, &prdEntrys, PRD_TABLE_ENTRY_COUNT,
                     request->ccb()->sg_list, request->ccb()->sg_count,
                     request->ccb()->data_length);
    } else if (request->data() && request->size()) {
        FillPrdTable(fPRDTable, &prdEntrys, PRD_TABLE_ENTRY_COUNT,
                     request->data(), request->size());
    } else
        prdEntrys = 0;

    FLOW("prdEntrys %d\n", prdEntrys);

    fCommandList->prdtl_flags_cfl = 0;
    fCommandList->cfl = 5; // 20 bytes, length in DWORDS
    memcpy((char *)fCommandTable->cfis, request->fis(), 20);

    fTestUnitReadyActive = request->is_test_unit_ready();
    if (request->is_atapi()) {
        // ATAPI PACKET is a 12 or 16 byte SCSI command
        memset((char *)fCommandTable->acmd, 0, 32);
        memcpy((char *)fCommandTable->acmd, request->ccb()->cdb,
               request->ccb()->cdb_length);
        fCommandList->a = 1;
    }

    if (isWrite)
        fCommandList->w = 1;
    fCommandList->prdtl = prdEntrys;
    fCommandList->prdbc = 0;

    if (wait_until_clear(&fRegs->tfd, ATA_BSY | ATA_DRQ, 1000000) < B_OK) {
        TRACE("ExecuteAtaRequest port %d: device is busy\n", fIndex);
        ResetPort();
        FinishTransfer();
        request->abort();
        return;
    }

    cpu_status cpu = disable_interrupts();
    acquire_spinlock(&fSpinlock);
    fCommandsActive |= 1;
    fRegs->ci = 1;
    FlushPostedWrites();
    release_spinlock(&fSpinlock);
    restore_interrupts(cpu);

    int tfd;
    status_t status = WaitForTransfer(&tfd, 20000000);

    FLOW("tfd %#x\n", tfd);
    FLOW("prdbc %ld\n", fCommandList->prdbc);
    FLOW("ci   0x%08" B_PRIx32 "\n", fRegs->ci);
    FLOW("is   0x%08" B_PRIx32 "\n", fRegs->is);
    FLOW("serr 0x%08" B_PRIx32 "\n", fRegs->serr);

    /*
    	TRACE("ci   0x%08" B_PRIx32 "\n", fRegs->ci);
    	TRACE("ie   0x%08" B_PRIx32 "\n", fRegs->ie);
    	TRACE("is   0x%08" B_PRIx32 "\n", fRegs->is);
    	TRACE("cmd  0x%08" B_PRIx32 "\n", fRegs->cmd);
    	TRACE("ssts 0x%08" B_PRIx32 "\n", fRegs->ssts);
    	TRACE("sctl 0x%08" B_PRIx32 "\n", fRegs->sctl);
    	TRACE("serr 0x%08" B_PRIx32 "\n", fRegs->serr);
    	TRACE("sact 0x%08" B_PRIx32 "\n", fRegs->sact);
    	TRACE("tfd  0x%08" B_PRIx32 "\n", fRegs->tfd);
    */

    if (fResetPort || status == B_TIMED_OUT) {
        fResetPort = false;
        ResetPort();
    }

    size_t bytesTransfered = fCommandList->prdbc;

    FinishTransfer();

    if (status == B_TIMED_OUT) {
        TRACE("ExecuteAtaRequest port %d: device timeout\n", fIndex);
        request->abort();
    } else {
        request->finish(tfd, bytesTransfered);
    }
}
コード例 #11
0
ファイル: cusp_shapes.c プロジェクト: WPettersson/regina
static void compute_translation(
    PositionedTet   *initial_ptet,
    PeripheralCurve which_curve,
    TraceDirection  which_direction,
    Complex         translation[2], /* returns translations based on ultimate   */
                                    /* and penultimate shapes                   */
    FillingStatus   which_structure)
{
    PositionedTet   ptet;
    int             i,
                    initial_strand,
                    strand,
                    *this_vertex,
                    near_strands,
                    left_strands;
    Complex         left_endpoint[2],   /*  left_endpoint[ultimate/penultimate]     */
                    right_endpoint[2],  /*  right_endpoint[ultimate/penultimate]    */
                    old_diff,
                    new_diff,
                    rotation;

    /*
     *  Place the near edge of the top vertex of the initial_ptet in the
     *  complex plane with its left endpoint at zero and its right endpoint at one.
     *  Trace the curve which_curve in the direction which_direction, using the
     *  shapes of the ideal tetrahedra to compute the position of endpoints of
     *  each edge we cross.  When we return to our starting point in the manifold,
     *  the position of the left endpoint (or the position of the right endpoint
     *  minus one) will tell us the translation.
     *
     *  Note that we are working in the orientation double cover of the cusp.
     *
     *  Here's how we keep track of where we are.  At each step, we are always
     *  at the near edge of the top vertex (i.e. the truncated vertex opposite
     *  the bottom face) of the PositionedTet ptet.  The curve (i.e. the
     *  meridian or longitude) may cross that edge several times.  The variable
     *  "strand" keeps track of which intersection we are at;  0 means we're at
     *  the strand on the far left, 1 means we're at the next strand, etc.
     */

    ptet            = *initial_ptet;
    initial_strand  = 0;
    strand          = initial_strand;
    for (i = 0; i < 2; i++)     /* i = ultimate, penultimate */
    {
        left_endpoint[i]    = Zero;
        right_endpoint[i]   = One;
    }

    do
    {
        /*
         *  Note the curve's intersection numbers with the near side and left side.
         */
        this_vertex =   ptet.tet->curve[which_curve][ptet.orientation][ptet.bottom_face];
        near_strands = this_vertex[ptet.near_face];
        left_strands = this_vertex[ptet.left_face];

        /*
         *  If we are tracing the curve backwards, negate the intersection numbers
         *  so the rest of compute_translation() can enjoy the illusion that we
         *  are tracing the curve forwards.
         */
        if (which_direction == trace_backwards)
        {
            near_strands = - near_strands;
            left_strands = - left_strands;
        }

        /*
         *  Does the current strand bend to the left or to the right?
         */

        if (strand < FLOW(near_strands, left_strands))
        {
            /*
             *  The current strand bends to the left.
             */

            /*
             *  The left_endpoint remains fixed.
             *  Update the right_endpoint.
             *
             *  The plan is to compute the vector old_diff which runs
             *  from left_endpoint to right_endpoint, multiply it by the
             *  complex edge parameter to get the vector new_diff which
             *  runs from left_endpoint to the new value of right_endpoint,
             *  and then add new_diff to left_endpoint to get the new
             *  value of right_endpoint itself.
             *
             *  Note that the complex edge parameters are always expressed
             *  relative to the right_handed Orientation, so if we are
             *  viewing this Tetrahedron relative to the left_handed
             *  Orientation, we must take the conjugate-inverse of the
             *  edge parameter.
             */
            for (i = 0; i < 2; i++)     /* i = ultimate, penultimate */
            {
                old_diff = complex_minus(right_endpoint[i], left_endpoint[i]);
                rotation = ptet.tet->shape[which_structure]->cwl[i][edge3_between_faces[ptet.near_face][ptet.left_face]].rect;
                if (ptet.orientation == left_handed)
                {
                    rotation        = complex_div(One, rotation);   /* invert . . .         */
                    rotation.imag   = - rotation.imag;              /* . . . and conjugate  */
                }
                new_diff = complex_mult(old_diff, rotation);
                right_endpoint[i] = complex_plus(left_endpoint[i], new_diff);
            }

            /*
             *  strand remains unchanged.
             */

            /*
             *  Move the PositionedTet onward, following the curve.
             */
            veer_left(&ptet);

        }
        else
        {
            /*
             *  The current strand bends to the right.
             *
             *  Proceed as above, but note that
             *
             *  (1) We now divide by the complex edge parameter
             *      instead of multiplying by it.
             *
             *  (2) We must adjust the variable "strand".  Some of the strands
             *      from the near edge may be peeling off to the left (in which
             *      case left_strands is negative), or some strands from the left
             *      edge may be joining those from the near edge in passing to
             *      the right edge (in which case left_strands is positive).
             *      Either way, the code "strand += left_strands" is correct.
             */

            for (i = 0; i < 2; i++)     /* i = ultimate, penultimate */
            {
                old_diff = complex_minus(left_endpoint[i], right_endpoint[i]);
                rotation = ptet.tet->shape[which_structure]->cwl[i][edge3_between_faces[ptet.near_face][ptet.right_face]].rect;
                if (ptet.orientation == left_handed)
                {
                    rotation        = complex_div(One, rotation);
                    rotation.imag   = - rotation.imag;
                }
                new_diff = complex_div(old_diff, rotation);
                left_endpoint[i] = complex_plus(right_endpoint[i], new_diff);
            }

            strand += left_strands;

            veer_right(&ptet);

        }
    }
    while ( ! same_positioned_tet(&ptet, initial_ptet) || strand != initial_strand);

    /*
     *  Write the computed translations, and return.
     */

    for (i = 0; i < 2; i++)     /* i = ultimate, penultimate */
        translation[i] = left_endpoint[i];
}
コード例 #12
0
ファイル: gluing_equations.c プロジェクト: DamianHeard/orb
static void compute_derivative(
	Triangulation	*manifold)
{
	Tetrahedron	*tet;
	Complex		z[3],
				d[3],
				*eqn_coef = NULL,
				dz[2];
	EdgeIndex	e;
	VertexIndex	v;
	FaceIndex	initial_side,
				terminal_side;
	int			init[2][2],
				term[2][2];
	double		m,
				l,
				a,
				b,
				*eqn_coef_00 = NULL,
				*eqn_coef_01 = NULL,
				*eqn_coef_10 = NULL,
				*eqn_coef_11 = NULL;
	int			i,
				j;

	for (tet = manifold->tet_list_begin.next;
		 tet != &manifold->tet_list_end;
		 tet = tet->next)
	{
		/*
		 *	Note the three edge parameters.
		 */

		for (i = 0; i < 3; i++)
			z[i] = tet->shape[filled]->cwl[ultimate][i].rect;

		/*
		 *	Set the derivatives of log(z0), log(z1) and log(z2)
		 *	with respect to the given coordinate system, as
		 *	indicated by the above table.
		 */

		switch (tet->coordinate_system)
		{
			case 0:
				d[0] = One;
				d[1] = complex_div(MinusOne, z[2]);
				d[2] = complex_minus(Zero, z[1]);
				break;

			case 1:
				d[0] = complex_minus(Zero, z[2]);
				d[1] = One;
				d[2] = complex_div(MinusOne, z[0]);
				break;

			case 2:
				d[0] = complex_div(MinusOne, z[1]);
				d[1] = complex_minus(Zero, z[0]);
				d[2] = One;
				break;
		}


		/*
		 *	Record this tetrahedron's contribution to the edge equations.
		 */

		for (e = 0; e < 6; e++)		/* Look at each of the six edges. */
		{
			/*
			 *	Find the matrix entry(ies) corresponding to the
			 *	derivative of the edge equation with respect to this
			 *	tetrahedron.  If the manifold is oriented it will be
			 *	a single entry in the complex matrix.  If the manifold
			 *	is unoriented it will be a 2 x 2 block in the real matrix.
			 */

			if (manifold->orientability == oriented_manifold || manifold->orientability == oriented_orbifold ) /* DJH */
				eqn_coef	= &tet->edge_class[e]->complex_edge_equation[tet->index];
			else
			{
				eqn_coef_00	= &tet->edge_class[e]->real_edge_equation_re[2 * tet->index];
				eqn_coef_01	= &tet->edge_class[e]->real_edge_equation_re[2 * tet->index + 1];
				eqn_coef_10	= &tet->edge_class[e]->real_edge_equation_im[2 * tet->index];
				eqn_coef_11	= &tet->edge_class[e]->real_edge_equation_im[2 * tet->index + 1];
			}

			/*
			 *	Add in the derivative of the log of the edge parameter
			 *	with respect to the chosen coordinate system.  Please
			 *	see the comment preceding this function for details.
			 */

			if (manifold->orientability == oriented_manifold || manifold->orientability == oriented_orbifold ) /* DJH */

				*eqn_coef = complex_plus(*eqn_coef, d[edge3[e]]);

			else
			{
				/*
				 *	These are the same a and b as in the comment
				 *	preceding this function.
				 */

				a = d[edge3[e]].real;
				b = d[edge3[e]].imag;

				if (tet->edge_orientation[e] == right_handed)
				{
					*eqn_coef_00 += a;
					*eqn_coef_01 -= b;
					*eqn_coef_10 += b;
					*eqn_coef_11 += a;
				}
				else
				{
					*eqn_coef_00 -= a;
					*eqn_coef_01 += b;
					*eqn_coef_10 += b;
					*eqn_coef_11 += a;
				}
			}
		}


		/*
		 *	Record this tetrahedron's contribution to the cusp equations.
		 */

		for (v = 0; v < 4; v++)		/* Look at each ideal vertex. */
		{
			/*
			 *	Note the Dehn filling coefficients on this cusp.
			 *	If the cusp is complete, use m = 1.0 and l = 0.0.
			 */

			if (tet->cusp[v]->is_complete) /* DJH : not sure ? */
			{
				m = 1.0;
				l = 0.0;
			}
			else
			{
				m = tet->cusp[v]->m;
				l = tet->cusp[v]->l;
			}

			/*
			 *	Find the matrix entry(ies) corresponding to the
			 *	derivative of the cusp equation with respect to this
			 *	tetrahedron.  If the manifold is oriented it will be
			 *	a single entry in the complex matrix.  If the manifold
			 *	is unoriented it will be a 2 x 2 block in the real matrix.
			 */
													/* DJH */
			if ( (manifold->orientability == oriented_manifold || manifold->orientability == oriented_orbifold ) && (
 				tet->cusp[v]->topology == torus_cusp || tet->cusp[v]->topology == Klein_cusp ) ) 
				eqn_coef = &tet->cusp[v]->complex_cusp_equation[tet->index];
			else
			{
				eqn_coef_00 = &tet->cusp[v]->real_cusp_equation_re[2 * tet->index];
				eqn_coef_01 = &tet->cusp[v]->real_cusp_equation_re[2 * tet->index + 1];
				eqn_coef_10 = &tet->cusp[v]->real_cusp_equation_im[2 * tet->index];
				eqn_coef_11 = &tet->cusp[v]->real_cusp_equation_im[2 * tet->index + 1];
			}

			/*
			 *	Each ideal vertex contains two triangular cross sections,
			 *	one right_handed and the other left_handed.  We want to
			 *	compute the contribution of each angle of each triangle
			 *	to the holonomy.  We begin by considering the right_handed
			 *	triangle, looking at each of its three angles.  A directed
			 *	angle is specified by its initial and terminal sides.
			 *	We find the number of strands of the Dehn filling curve
			 *	passing from the initial side to the terminal side;
			 *	it is  m * (number of strands of meridian)
			 *	+ l * (number of strands of longitude), where (m,l) are
			 *	the Dehn filling coefficients (in practice, m and l need
			 *	not be integers, but it's simpler to imagine them to be
			 *	integers as you try to understand the following code).
			 *	The number of strands of the Dehn filling curves passing
			 *	from the initial to the terminal side is multiplied by
			 *	the derivative of the log of the complex angle, to yield
			 *	the contribution to the derivative matrix.  If the manifold
			 *	is oriented, that complex number is added directly to
			 *	the relevant matrix entry.  If the manifold is unoriented,
			 *	we convert the complex number to a 2 x 2 real matrix
			 *	(cf. the comments preceding this function) and add it to
			 *	the appropriate 2 x 2 block of the real derivative matrix.
			 *	The 2 x 2 matrix for the left_handed triangle is modified
			 *	to account for the fact that although the real part of the
			 *	derivative of the log (i.e. the compression/expansion
			 *	factor) is the same, the imaginary part (i.e. the rotation)
			 *	is negated.  [Note that in computing the edge equations
			 *	the real part was negated, while for the cusp equations
			 *	the imaginary part is negated.  I will leave an explanation
			 *	of the difference as an exercise for the reader.]
			 *
			 *	Note that we cannot possibly handle curves on the
			 *	left_handed sheet of the orientation double cover of
			 *	a cusp of an oriented manifold.  The reason is that the
			 *	log of the holonomy of the Dehn filling curve is not
			 *	a complex analytic function of the shape of the tetrahedron
			 *	(it's the complex conjugate of such a function).  I.e.
			 *	it doesn't have a derivative in the complex sense.  This
			 *	is why we make the convention that all peripheral curves
			 *	in oriented manifolds lie on the right_handed sheet of
			 *	the double cover.
			 */

			for (initial_side = 0; initial_side < 4; initial_side++)
			{
				if (initial_side == v)
					continue;

				terminal_side = remaining_face[v][initial_side];

				/*
				 *	Note the intersection numbers of the meridian and
				 *	longitude with the initial and terminal sides.
				 */

				for (i = 0; i < 2; i++)	{		/* which curve */
					for (j = 0; j < 2; j++)	{	/* which sheet */
						init[i][j] = tet->curve[i][j][v][initial_side];
						term[i][j] = tet->curve[i][j][v][terminal_side];
					}
				}

				/*
				 *	For each triangle (right_handed and left_handed),
				 *	multiply the number of strands of the Dehn filling
				 *	curve running from initial_side to terminal_side
				 *	by the derivative of the log of the edge parameter.
				 */

				for (i = 0; i < 2; i++)	/* which sheet */
					dz[i] = complex_real_mult(
						m * FLOW(init[M][i],term[M][i]) +	l * FLOW(init[L][i],term[L][i]),
						d[ edge3_between_faces[initial_side][terminal_side] ]
					);

				/*
				 *	If the manifold is oriented, the Dehn filling curve
				 *	must lie of the right_handed sheet of the orientation
				 *	double cover (cf. above).  Add its contributation to
				 *	the cusp equation.
				 */
													/* DJH */
				if (manifold->orientability == oriented_manifold || manifold->orientability == oriented_orbifold )

					*eqn_coef = complex_plus(*eqn_coef, dz[right_handed]);

				/* "else" follows below */

				/*
				 *	If the manifold is unoriented, treat the right_ and
				 *	left_handed sheets separately.  Add in the contribution
				 *	of the right_handed sheet normally.  For the left_handed
				 *	sheet, we must account for the fact that even though
				 *	the modulus of the derivative (i.e. the expansion/
				 *	contraction factor) is correct, its argument (i.e. the
				 *	angle of rotation) is the negative of what it should be.
				 */

				else
				{
					a = dz[right_handed].real;
					b = dz[right_handed].imag;
					*eqn_coef_00 += a;
					*eqn_coef_01 -= b;
					*eqn_coef_10 += b;
					*eqn_coef_11 += a;

					a = dz[left_handed].real;
					b = dz[left_handed].imag;
					*eqn_coef_00 += a;
					*eqn_coef_01 -= b;
					*eqn_coef_10 -= b;
					*eqn_coef_11 -= a;
				}

			}
		}
	}
}
コード例 #13
0
	void addEdge(int from, int to, FLOW cost) {
		edges[from].push_back(Edge(to, cost, size_of(edges[to])));
		edges[to].push_back(Edge(from, FLOW(), size_of(edges[from]) - 1));
	}
コード例 #14
0
ファイル: ant.c プロジェクト: gpolo/QAP
int asymmetric_calc_reduction(QAP_t *prob, QAP_solution_t *sol, int r, int s){
    int k;
    int reduction =  prob->dist[r][r] * (FLOW(prob, sol, s, s) - FLOW(prob, sol, r, r)) + 
                     prob->dist[r][s] * (FLOW(prob, sol, s, r) - FLOW(prob, sol, r, s)) +
                     prob->dist[s][r] * (FLOW(prob, sol, r, s) - FLOW(prob, sol, s, r)) + 
                     prob->dist[s][s] * (FLOW(prob, sol, r, r) - FLOW(prob, sol, s, s));

    for (k = 0; k < prob->size; k++){
         if (k == r || k == s) continue;   
         reduction += prob->dist[k][r] * (FLOW(prob, sol, k, s) - FLOW(prob, sol, k, r)) +
                      prob->dist[k][s] * (FLOW(prob, sol, k, r) - FLOW(prob, sol, k, s)) + 
                      prob->dist[r][k] * (FLOW(prob, sol, s, k) - FLOW(prob, sol, r, k)) +
                      prob->dist[s][k] * (FLOW(prob, sol, r, k) - FLOW(prob, sol, s, k));

    }
    return reduction;
}
コード例 #15
0
ファイル: mds.c プロジェクト: AlessandroBeggiato/MultiUbic
void readMDS (char *mdsFileName){
	FILE *infile;
	int i,j;
	int transitive = 0;
	int counter = 0;
	/* Open the file, read the header. */
	if (!(infile = fopen(mdsFileName, "r"))){
		fprintf(stderr,"'%s': cannot open for reading\n", mdsFileName);
		exit(EXIT_FAILURE);
	}

	ReadToken(infile);
	if (!sbuf || strcmp(sbuf, "MDS")) {
		fprintf(stderr,"Syntax error in the policy file: MDS expected\n");
		exit(EXIT_FAILURE);
	}
	ReadNewline(infile);
	ReadToken(infile);
	if (!sbuf || !strcmp(sbuf, "TRANSITIVE"))transitive = 1;
	else if (!sbuf || strcmp(sbuf, "INTRANSITIVE")){
		fprintf(stderr,"Syntax error in the policy file: TRANSITIVE or INTRANSITIVE expected\n");
		exit(EXIT_FAILURE);
	}
	ReadNewline(infile);
	ReadToken(infile);
	if (!sbuf || strcmp(sbuf, "LVL")) {
		fprintf(stderr,"Syntax error in the policy file: LVL expected\n");
		exit(EXIT_FAILURE);
	}
	ReadToken(infile);
	if(!sbuf){
		fprintf(stderr,"Syntax error in the policy file: integer value expected\n");
		exit(EXIT_FAILURE);
	}
	//header read, I can now allocate the policy
	initializeMDS(atoi(sbuf));
	policy->isTransitive=transitive;
	while(counter < policy->levelNumber){
		ReadNewline(infile);
		ReadToken(infile);
		if(!sbuf || atoi(sbuf)!=counter){
			fprintf(stderr,"Syntax error in the policy file: %d expected at line %d\n",counter+1, counter+4);
			exit(EXIT_FAILURE);
		}
		ReadToken(infile);
		if(!sbuf){
			fprintf(stderr,"Syntax error in the policy file: levelName expected at line %d \n",counter+4);
			exit(EXIT_FAILURE);
		}
		policy->levelNames[counter]=malloc(strlen(sbuf));
		sprintf(policy->levelNames[counter],"%s",sbuf);
		++counter;
	}
	ReadNewline(infile);
	ReadToken(infile);
	if (!sbuf || strcmp(sbuf, "POLICY")) {
		fprintf(stderr,"Syntax error in the policy file: POLICY expected\n");
		exit(EXIT_FAILURE);
	}
	ReadNewline(infile);
	ReadToken(infile);
	while(sbuf){
		if(!sbuf){
			fprintf(stderr,"Syntax error in the policy file: integer value expected at line %d\n", counter+5);
			exit(EXIT_FAILURE);
		}
		i = atoi(sbuf);
		ReadToken(infile);
		if (!sbuf || strcmp(sbuf, "TO")) {
			fprintf(stderr,"Syntax error in the policy file: TO expected at line %d\n", counter+5);
			exit(EXIT_FAILURE);
		}
		ReadToken(infile);
		if(!sbuf){
			fprintf(stderr,"Syntax error in the policy file: integer value expected at line %d\n", counter+5);
			exit(EXIT_FAILURE);
		}
		j=atoi(sbuf);
		FLOW(i,j) = 1;
		++counter;
		ReadNewline(infile);
		ReadToken(infile);
	}
}