Exemple #1
0
/* xboundp - is this a value bound to this symbol? */
LVAL xboundp(void)
{
    LVAL sym;
    sym = xlgasymbol();
    xllastarg();
    return (boundp(sym) ? s_true : NIL);
}
ILOSTLBEGIN

IloRangeArray profit_constraints(graph g, IloModel model, IloNumVarArray x, IloNumVarArray p, IloNumVarArray z, int **columns) {
  string s;
  IloRangeArray c(model.getEnv());
  c.add(assignment_ineq(g, model, x, columns));
  for(int i = 0; i < g->bidders; i++) {
  	for(int edge = 0; edge < g->dbidder[i]; edge++) {
  		int k = g->b_adj[i][edge];
      IloNumExpr e(model.getEnv());
      for(int other_edge = 0; other_edge < g->dbidder[i]; other_edge++) {
        int j = g->b_adj[i][other_edge];
        e += g->adj[i][j]*x[columns[i][j]];
      }
      e += - z[i] + p[k];
      c.add(e >= g->adj[i][k]);
      s = "b_" + itos(i) + "," + itos(k);
      c[c.getSize()-1].setName(s.c_str());
  	}
  }
  for(int i = 0; i < g->bidders; i++) {
    IloNumExpr e(model.getEnv());
    e += z[i];
    for(int edge = 0; edge < g->dbidder[i]; edge++) {
      int j = g->b_adj[i][edge];
      e -= g->adj[i][j]*x[columns[i][j]];
    }    
    c.add(e <= 0);
    s = "c_" + itos(i);
    c[c.getSize()-1].setName(s.c_str());
  }
  for(int i = 0; i < g->bidders; i++) {
    for(int edge = 0; edge < g->dbidder[i]; edge++) {
      int j = g->b_adj[i][edge];
      IloNumExpr e(model.getEnv());
      e += z[i] - p[j] - boundp(j)*x[columns[i][j]];
      c.add(e >= - boundp(j));
      s = "e_" + itos(i) + "," + itos(j);
      c[c.getSize()-1].setName(s.c_str());
    }
  }
  return c;
}
void profit_create_vars(graph g, IloModel model, IloNumVarArray x, IloNumVarArray p, IloNumVarArray z, int **columns) {
  IloEnv env = model.getEnv();
  string s;
  assignment_vars(g, model, x, columns);  
  for(int j = 0; j < g->items; j++) {
    s = "p_" + itos(j);
    p.add(IloNumVar(env, 0.0, boundp(j), ILOFLOAT, s.c_str()));
    // p.add(IloNumVar(env, lowerp(j), boundp(j), ILOFLOAT, s.c_str()));
  }
  for(int i = 0; i < g->bidders; i++) {
    s = "z_" + itos(i);
    z.add(IloNumVar(env, 0.0, boundu(i), ILOFLOAT, s.c_str()));
  }
}
void profit_load(graph g, IloCplex cplex, IloModel model, IloNumVarArray x, IloNumVarArray p, IloNumVarArray z, int **columns, vector<int>& allocation, vector<double>& pricing) {
  IloNumVarArray startVar(model.getEnv());
  IloNumArray startVal(model.getEnv());
  for(int j = 0; j < g->items; j++) {
    if(boundp(j) > 0){
      startVar.add(p[j]);
      startVal.add(pricing[j]);
    }
  }
  for(int i = 0; i < g->bidders; i++) {
    for(int e = 0; e < g->dbidder[i]; e++) {
      int j = g->b_adj[i][e];
      startVar.add(x[columns[i][j]]);
      startVal.add(allocation[i] == j ? 1 : 0);
    }
  }
  for(int i = 0; i < g->bidders; i++) {
    if(boundu(i) > 0){
      startVar.add(z[i]);
      startVal.add(allocation[i] != -1 ? pricing[allocation[i]] : 0);
    }
  }
  cplex.addMIPStart(startVar, startVal);
}
  void Refinement ::
  ValidateRefinedMesh (Mesh & mesh, 
		       Array<INDEX_2> & parents)
  {
    // int i, j, k;
  
    // homotopy method

    int ne = mesh.GetNE();

    int cnttrials = 100;
    int wrongels = 0;
    for (int i = 1; i <= ne; i++)
      if (mesh.VolumeElement(i).CalcJacobianBadness (mesh.Points()) > 1e10)
	{
	  wrongels++;
	  mesh.VolumeElement(i).flags.badel = 1;
	}
      else
	mesh.VolumeElement(i).flags.badel = 0;

    double facok = 0;
    double factry;

    BitArray illegalels(ne);
    illegalels.Clear();

      
    if (wrongels)
      {
	cout << "WARNING: " << wrongels << " illegal element(s) found" << endl;

	int np = mesh.GetNP();
	Array<Point<3> > should(np);
	Array<Point<3> > can(np);

	for (int i = 1; i <= np; i++)
	  {
	    should.Elem(i) = can.Elem(i) = mesh.Point(i);
	  }

	for (int i = 1; i <= parents.Size(); i++)
	  {
	    if (parents.Get(i).I1())
	      can.Elem(i) = Center (can.Elem(parents.Get(i).I1()),
				    can.Elem(parents.Get(i).I2()));
	  }

	BitArray boundp(np);
	boundp.Clear();
	for (int i = 1; i <= mesh.GetNSE(); i++)
	  {
	    const Element2d & sel = mesh.SurfaceElement(i);
	    for (int j = 1; j <= sel.GetNP(); j++)
	      boundp.Set(sel.PNum(j));
	  }


	(*testout) << "bpoints:" << endl;
	for (int i = 1; i <= np; i++)
	  if (boundp.Test(i))
	    (*testout) << i << endl;

	double lam = 0.5;

	while (facok < 1-1e-8 && cnttrials > 0)
	  {
	    lam *= 4;
	    if (lam > 2) lam = 2;

	    do
	      {
		//	      cout << "trials: " << cnttrials << endl;
		lam *= 0.5;
		cnttrials--;

		cout << "lam = " << lam << endl;

		factry = lam + (1-lam) * facok;
		cout << "trying: " << factry << endl;

		for (int i = 1; i <= np; i++)
		  if (boundp.Test(i))
		    {
		      for (int j = 0; j < 3; j++)
			mesh.Point(i)(j) = 
			  lam * should.Get(i)(j) +
			  (1-lam) * can.Get(i)(j);
		    }
		  else
		    mesh.Point(i) = Point<3> (can.Get(i));
	      
		//	      (*testout) << "bad els: " << endl;
		wrongels = 0;
		for (int i = 1; i <= ne; i++)
		  {
		    if (!illegalels.Test(i) && 
			mesh.VolumeElement(i).
			CalcJacobianBadness(mesh.Points()) > 1e10)
		      {
			wrongels++;
			Element & el = mesh.VolumeElement(i);
			el.flags.badel = 1;
		     
		      
			if (lam < 1e-4)
			  illegalels.Set(i);
 

			/*
			  (*testout) << i << ": ";
			  for (j = 1; j <= el.GetNP(); j++)
			  (*testout) << el.PNum(j) << " ";
			  (*testout) << endl;
			*/
		      }
		    else
		      mesh.VolumeElement(i).flags.badel = 0;
		  }
		cout << "wrongels = " << wrongels << endl;
	      }
	    while (wrongels && cnttrials > 0);

	    mesh.CalcSurfacesOfNode();
	    MeshingParameters dummymp;
	    mesh.ImproveMeshJacobian (dummymp, OPT_WORSTCASE);	      
	  
	    facok = factry;
	    for (int i = 1; i <= np; i++)
	      can.Elem(i) = mesh.Point(i);
	  }
      }


      
    for (int i = 1; i <= ne; i++)
      {
	if (illegalels.Test(i))
	  {
	    cout << "illegal element: " << i << endl;
	    mesh.VolumeElement(i).flags.badel = 1;	
	  }
	else
	  mesh.VolumeElement(i).flags.badel = 0;	
      }
  
    /*
      if (cnttrials <= 0)
      {
      cerr << "ERROR: Sorry, illegal elements:" << endl;
      }
    */
  }