Пример #1
0
int main(int argc,  char **argv)
{

#if doMPI
    if ( MPI_SUCCESS != MPI_Init( & argc , & argv ) ) {
        std::cerr << "MPI_Init FAILED" << std::endl ;
        std::abort();
    }
#endif

    Verifier vf;
    vf.verify(argc, argv);


#if doMPI
#endif
    //  MPI_Finalize();

    return 0;
}
Пример #2
0
void VNS::run() {
	const ProcessCount pCount = instance().processes().size();
	// read configuration
	const uint32_t kMin = hasParam("kMin") ? param<uint32_t>("kMin") : 2;
	const uint32_t kMax = hasParam("kMax") ? param<uint32_t>("kMax") : 5;
	const uint32_t trials = hasParam("trials") ? param<uint32_t>("trials") : 5;
	const uint32_t maxInf = hasParam("maxInf") ? param<uint32_t>("maxInf") : 3;
	m_maxTrialsLS = param<uint64_t>("maxTrialsLS", defaultMaxTrialsLS());
	m_maxSamplesLS = param<uint64_t>("maxSamplesLS", pCount);
	// initialize RNG
	m_rng.seed(seed());
	// initialize shaker
	SmartShaker shaker(trials, maxInf);
	shaker.init(instance(), initial(), seed(), flag());
	// initialize solution info
	m_current.reset(new SolutionInfo(instance(), initial()));
	// run local search to get starting solution
	localSearch();
	// set best and publish to pool
	m_best = std::move(m_current);
	pool().push(m_best->objective(), m_best->solution());
	// start VNS
	uint64_t it = 0;
	uint32_t k = kMin;
	uint64_t syncPeriod = 100;
	uint64_t diversifyPeriod = 100;
	uint64_t concentratePeriod = 100;
	#ifdef CHECK_VNS
	Verifier v;
	#endif
	while (!interrupted()) {
		++it;
		// periodically sync with best result
		if (it % syncPeriod == 0) {
			SolutionPool::Entry entry;
			if (pool().best(entry)) {
				if (entry.obj() < m_best->objective()) {
					m_best.reset(new SolutionInfo(instance(), initial(), *(entry.ptr())));
					k = kMin;
				}
			}
		}
		// periodically start from a good solution different from the best known one
		if (it % diversifyPeriod == 25) {
			SolutionPool::Entry hdEntry;
			if (pool().randomHighDiversity(hdEntry)) {
				m_current.reset(new SolutionInfo(instance(), initial(), *hdEntry.ptr()));
			}
		} else if (it % concentratePeriod == 75) {
			SolutionPool::Entry hqEntry;
			if (pool().randomHighQuality(hqEntry)) {
				m_current.reset(new SolutionInfo(instance(), initial(), *hqEntry.ptr()));
			}
		} else {
			// most of the times start from the best known solution
			m_current.reset(new SolutionInfo(*m_best));
		}
		// make random jump
		shaker.shake(k, *m_current);
		// since shaking might take a long time, check for interruption
		if (interrupted()) {
			#ifdef TRACE_VNS
			std::cout << "VNS - Interrupted during shake @ iteration " << it << std::endl;
			#endif
			break;
		}
		#ifdef CHECK_VNS
		//  verify shaking led to a feasible solution
		if (!v.verify(instance(), initial(), m_current->solution()).feasible()) {
			throw std::runtime_error("VNS - Shaking lead to an unfeasible solution");
		}
		#endif
		// do a local search
		localSearch();
		#ifdef CHECK_VNS
		//  verify shaking led to a feasible solution
		if (!v.verify(instance(), initial(), m_current->solution()).feasible()) {
			throw std::runtime_error("VNS - Local search lead to an unfeasible solution");
		}
		#endif
		// update best solution if improved if needed
		if (m_current->objective() < m_best->objective()) {
			m_best = std::move(m_current);
			#ifdef TRACE_VNS
			std::cout << "VNS - Improvement found @ iteration " << it << ": " << m_best->objective() << std::endl;
			#endif
			pool().push(m_best->objective(), m_best->solution());
			// restart from small neighborhood
			k = kMin;
		} else {
			// move to another neighborhood
			k = kMin + (k - kMin + 1) % (kMax - kMin + 1);
		}
	}
	#ifdef TRACE_VNS
	std::cout << "VNS - Completed after " << it << " iterations" << std::endl;
	std::cout << "VNS - Failures per shake " << shaker.failuresPerShake() << std::endl;
	#endif
	signalCompletion();
}
Пример #3
0
int main(int argc, char** argv) {
  Galois::StatManager statManager;
  LonestarStart(argc, argv, name, desc, url);

  graph = new Graph();
  {
    Mesh m;
    m.read(graph, filename.c_str(), detAlgo == nondet);
    Verifier v;
    if (!skipVerify && !v.verify(graph)) {
      std::cerr << "bad input mesh\n";
      assert(0 && "Refinement failed");
      abort();
    }
  }

  std::cout << "configuration: " << std::distance(graph->begin(), graph->end())
	    << " total triangles, " << std::count_if(graph->begin(), graph->end(), is_bad(graph)) << " bad triangles\n";

  Galois::Statistic("MeminfoPre1", GaloisRuntime::MM::pageAllocInfo());
  Galois::preAlloc(15 * numThreads + GaloisRuntime::MM::pageAllocInfo() * 10);
  Galois::Statistic("MeminfoPre2", GaloisRuntime::MM::pageAllocInfo());

  Galois::StatTimer T;
  T.start();

  if (detAlgo == nondet)
    Galois::do_all_local(*graph, Preprocess());
  else
    std::for_each(graph->begin(), graph->end(), Preprocess());

  Galois::Statistic("MeminfoMid", GaloisRuntime::MM::pageAllocInfo());
  
  Galois::StatTimer Trefine("refine");
  Trefine.start();
  using namespace GaloisRuntime::WorkList;
  
  typedef LocalQueues<dChunkedLIFO<256>, ChunkedLIFO<256> > BQ;
  typedef ChunkedAdaptor<false,32> CA;
  
  switch (detAlgo) {
    case nondet: 
      Galois::for_each_local<CA>(wl, Process<>()); break;
    case detBase:
      Galois::for_each_det(wl.begin(), wl.end(), Process<>()); break;
    case detPrefix:
      Galois::for_each_det(wl.begin(), wl.end(), Process<detPrefix>(), Process<>());
      break;
    case detDisjoint:
      Galois::for_each_det(wl.begin(), wl.end(), Process<detDisjoint>()); break;
    default: std::cerr << "Unknown algorithm" << detAlgo << "\n"; abort();
  }
  Trefine.stop();
  T.stop();
  
  Galois::Statistic("MeminfoPost", GaloisRuntime::MM::pageAllocInfo());
  
  if (!skipVerify) {
    int size = Galois::ParallelSTL::count_if(graph->begin(), graph->end(), is_bad(graph));
    if (size != 0) {
      std::cerr << size << " bad triangles remaining.\n";
      assert(0 && "Refinement failed");
      abort();
    }
    Verifier v;
    if (!v.verify(graph)) {
      std::cerr << "Refinement failed.\n";
      assert(0 && "Refinement failed");
      abort();
    }
    std::cout << "Refinement OK\n";
  }

  return 0;
}