#ifdef DOC_BUILD_INTERNAL
#endif
#include "meta.h"
ARRAY meta_GetDelta(METASTATE Meta)
{
  return Meta->delta;
}
void meta_SetDelta(METASTATE Meta, ARRAY Delta)
{
  Meta->delta = Delta;
}
unsigned meta_GetSize(METASTATE Meta)
{
  return Meta->size;
}
void meta_SetSize(METASTATE Meta, unsigned Size)
{
  Meta->size = Size;
}
METASTATE meta_Create(SCLSTATE State, TWFO Twfo, METAHEUR Mode)
{
  METASTATE meta;
  MEMORY mem;
  mem = state_GetMemory(State);
  meta = memory_Malloc(mem, sizeof(METASTATE_NODE));
  meta->sclstate = State;
  meta->twfo = Twfo;
  meta->memory = state_GetMemory(State);
  meta->symbstate = state_GetSymbstate(State);
  meta->termstate = state_GetTermstate(State);
  meta->folstate = state_GetFolstate(State);
  meta->sstate = state_GetSubststate(State);
  meta->thetaupq = NULL;
  meta->thetaindex = distrn_Create(mem);
  meta->lambdaindex = distrn_Create(mem);
  meta->delta = array_Create(mem,((state_GetNumberInputLits(State)/array_GetSize(state_GetClauses(State)))*2));
  meta->size = 0;
  meta->actheur = Mode;
  meta->lmodgrow = (HLMDGSTATE)NULL;
  meta->hlcl = (HLCLSTATE)NULL;
  switch (Mode) {
  case META_LMODEL_GROW:
    meta->lmodgrow = hlmdg_Create(State, Twfo);
    break;
  case META_LCL:
    meta->hlcl = hlcl_Create(State, Twfo);
    break;
  default:
    misc_StartErrorReport();
    misc_ErrorReport("\n In %s:", __func__);
    misc_ErrorReport("\n Heuristic number %u unknown.", Mode);
    misc_FinishErrorReport();
  }
  return meta;
}
unsigned meta_GetNumberActiveAtoms(METASTATE Meta)
{
  switch (Meta->actheur) {
  case META_LMODEL_GROW:
    return hlmdg_ActiveAtoms(Meta->lmodgrow);
    break;
  case META_LCL:
    return hlcl_ActiveAtoms(Meta->hlcl);
    break;
  default:
    misc_StartErrorReport();
    misc_ErrorReport("\n In %s:", __func__);
    misc_ErrorReport("\n Heuristic number %u unknown.", Meta->actheur);
    misc_FinishErrorReport();
  }
  return 0;
}
void meta_Delete(METASTATE meta)
{
  MEMORY mem;
  mem = meta->memory;
  distrn_Delete(mem, meta->thetaindex);
  distrn_Delete(mem, meta->lambdaindex);
  array_Delete(mem, meta->delta);
  if (meta->lmodgrow)
    hlmdg_Delete(mem, meta->lmodgrow);
  if (meta->hlcl)
    hlcl_Delete(mem, meta->hlcl);
  memory_Free(mem, meta, sizeof(METASTATE_NODE));
}
BOOL meta_PerformReduction(SCLSTATE State, METASTATE Meta)
{
  switch (Meta->actheur) {
  case META_LMODEL_GROW:
    return hlmdg_PerformReduction(State, Meta->lmodgrow);
    break;
  case META_LCL:
    return hlcl_PerformReduction(State, Meta->hlcl);
    break;
  default:
    misc_StartErrorReport();
    misc_ErrorReport("\n In %s:", __func__);
    misc_ErrorReport("\n Heuristic number %u unknown.", Meta->actheur);
    misc_FinishErrorReport();
  }
  return FALSE;
}
BOOL meta_PerformSATTest(SCLSTATE State,METASTATE Meta)
{
  switch (Meta->actheur) {
  case META_LMODEL_GROW:
    return hlmdg_PerformSATTest(State, Meta->lmodgrow);
    break;
  case META_LCL:
    return hlcl_PerformSATTest(State, Meta->hlcl);
    break;
  default:
    misc_StartErrorReport();
    misc_ErrorReport("\n In %s:", __func__);
    misc_ErrorReport("\n Heuristic number %u unknown.", Meta->actheur);
    misc_FinishErrorReport();
  }
  return FALSE;
}
BOOL meta_PerformSATAbstraction(SCLSTATE State,METASTATE Meta)
{
  switch (Meta->actheur) {
  case META_LMODEL_GROW:
    return hlmdg_PerformSATAbstraction(State, Meta->lmodgrow);
    break;
  case META_LCL:
    return hlcl_PerformSATAbstraction(State, Meta->hlcl);
    break;
  default:
    misc_StartErrorReport();
    misc_ErrorReport("\n In %s:", __func__);
    misc_ErrorReport("\n Heuristic number %u unknown.", Meta->actheur);
    misc_FinishErrorReport();
  }
  return FALSE;
}
BOOL meta_ExtendActiveLiterals(SCLSTATE State, METASTATE Meta, TRAIL Trail, TWFO Twfo, BOOL *DetectSAT)
{
  switch (Meta->actheur) {
  case META_LMODEL_GROW:
    return hlmdg_ExtendActiveLiterals(State, Meta->lmodgrow, Trail, Twfo, DetectSAT);
    break;
  case META_LCL:
    return hlcl_ExtendActiveLiterals(State, Meta->hlcl, Trail, DetectSAT);
    break;
  default:
    misc_StartErrorReport();
    misc_ErrorReport("\n In %s:", __func__);
    misc_ErrorReport("\n Heuristic number %u unknown.", Meta->actheur);
    misc_FinishErrorReport();
  }
  return FALSE;
}
void meta_UpdateLearnedClause(SCLSTATE State, METASTATE Meta, TRAIL trail, CLAUSE Clause, SUBST Subst)
{
  switch (Meta->actheur) {
  case META_LMODEL_GROW:
    hlmdg_UpdateLearnedClause(State, Meta->lmodgrow, trail, Clause, Subst);
    break;
  case META_LCL:
    hlcl_UpdateLearnedClause(State, Meta->hlcl, trail, Clause, Subst);
    break;
  default:
    misc_StartErrorReport();
    misc_ErrorReport("\n In %s:", __func__);
    misc_ErrorReport("\n Heuristic number %u unknown.", Meta->actheur);
    misc_FinishErrorReport();
  }
  return;
}
 TERM meta_SelectNextTrailLiteral(SCLSTATE State, METASTATE Meta, TRAIL Trail, TWFO Twfo)
{
  switch (Meta->actheur) {
  case META_LMODEL_GROW:
    return hlmdg_NextTrailLiteral(State, Meta->lmodgrow, Trail, Twfo);
    break;
  case META_LCL:
    return hlcl_NextTrailLiteral(State, Meta->hlcl, Trail, Twfo);
    break;
  default:
    misc_StartErrorReport();
    misc_ErrorReport("\n In %s:", __func__);
    misc_ErrorReport("\n Heuristic number %u unknown.", Meta->actheur);
    misc_FinishErrorReport();
  }
  return (TERM)NULL;
}
void meta_UpdateBacktrack(SCLSTATE State, METASTATE Meta, TRAIL Trail, TWFO Twfo, unsigned Level)
{
  switch (Meta->actheur) {
  case META_LMODEL_GROW:
    hlmdg_UpdateBacktrack(State, Meta->lmodgrow, Trail, Twfo, Level);
    break;
  case META_LCL:
    hlcl_UpdateBacktrack(State, Meta->hlcl, Trail, Twfo, Level);
    break;
  default:
    misc_StartErrorReport();
    misc_ErrorReport("\n In %s:", __func__);
    misc_ErrorReport("\n Heuristic number %u unknown.", Meta->actheur);
    misc_FinishErrorReport();
  }
  return;
}
void meta_UpdateRestart(SCLSTATE State, METASTATE Meta, TRAIL Trail, TWFO Twfo)
{
  switch (Meta->actheur) {
  case META_LMODEL_GROW:
    hlmdg_UpdateRestart(State, Meta->lmodgrow, Trail, Twfo);
    break;
  case META_LCL:
    hlcl_UpdateRestart(State, Meta->hlcl, Trail, Twfo);
    break;
  default:
    misc_StartErrorReport();
    misc_ErrorReport("\n In %s:", __func__);
    misc_ErrorReport("\n Heuristic number %u unknown.", Meta->actheur);
    misc_FinishErrorReport();
  }
  return;
}
void meta_UpdateReduction(SCLSTATE State, METASTATE Meta, TRAIL Trail, TWFO Twfo)
{
  switch (Meta->actheur) {
  case META_LMODEL_GROW:
    hlmdg_UpdateReduction(State, Meta->lmodgrow, Trail, Twfo);
    break;
  case META_LCL:
    hlcl_UpdateReduction(State, Meta->hlcl, Trail, Twfo);
    break;
  default:
    misc_StartErrorReport();
    misc_ErrorReport("\n In %s:", __func__);
    misc_ErrorReport("\n Heuristic number %u unknown.", Meta->actheur);
    misc_FinishErrorReport();
  }
  return;
}
void meta_UpdateNewResolution(SCLSTATE State, METASTATE Meta, TERM Atom, CLAUSE Resolvent, SUBST Grounding, ARRAY Parents)
{
  switch (Meta->actheur) {
  case META_LMODEL_GROW:
    hlmdg_UpdateNewResolution(State, Meta->lmodgrow, Atom, Resolvent, Grounding, Parents);
    break;
  case META_LCL:
    hlcl_UpdateNewResolution(State, Meta->hlcl, Atom, Resolvent, Grounding, Parents);
    break;
  default:
    misc_StartErrorReport();
    misc_ErrorReport("\n In %s:", __func__);
    misc_ErrorReport("\n Heuristic number %u unknown.", Meta->actheur);
    misc_FinishErrorReport();
  }
  return;
}
METAHEUR meta_PickHeuristic(SCLSTATE State)
{
  if (hlcl_IsApplicable(State)) {
    return META_LCL;
  } else {
    return META_LMODEL_GROW;
  }
}
void meta_Print(METASTATE Meta)
{
  switch (Meta->actheur) {
  case META_LMODEL_GROW:
    hlmdg_Print(Meta->sclstate, Meta->lmodgrow);
    break;
  case META_LCL:
    hlcl_Print(Meta->sclstate, Meta->hlcl);
    break;
  default:
    misc_StartErrorReport();
    misc_ErrorReport("\n In %s:", __func__);
    misc_ErrorReport("\n Heuristic number %u unknown.", Meta->actheur);
    misc_FinishErrorReport();
  }
  return;
}
void meta_PrintStat(METASTATE Meta)
{
  switch (Meta->actheur) {
  case META_LMODEL_GROW:
    hlmdg_PrintStat(Meta->lmodgrow);
    break;
  case META_LCL:
    hlcl_PrintStat(Meta->hlcl);
    break;
  default:
    misc_StartErrorReport();
    misc_ErrorReport("\n In %s:", __func__);
    misc_ErrorReport("\n Heuristic number %u unknown.", Meta->actheur);
    misc_FinishErrorReport();
  }
  return;
}
