示例#1
0
void hypergraph::initialize_cut_sizes(int numParts) {
#ifdef DEBUG_HYPERGRAPH
  assert(numPartitions >= 1);
  assert(partitionCuts.getLength() >= 1);
  assert(partitionVector.getLength() >= numVertices);
  assert(partitionVectorOffsets.getLength() > 1);
#endif

  for (int i = 0; i < number_of_partitions_; ++i) {
    partition_cuts_[i] = cut_size(numParts, i);
  }
}
示例#2
0
void hypergraph::check_partition(int numPartition, int nP, int maxWt) const {
  ds::dynamic_array<int> partWts(nP);

  int cut = cut_size(nP, numPartition);
  assert(cut == partition_cuts_[numPartition]);

  for (int i = 0; i < nP; ++i)
    partWts[i] = 0;

  int offset = partition_vector_offsets_[numPartition];

  for (int i = 0; i < number_of_vertices_; ++i)
    partWts[partition_vector_[offset + i]] += vertex_weights_[i];

  check_part_weights_are_less_than(partWts, nP, maxWt);
}
示例#3
0
void hypergraph::check_partitions(int nP, int maxWt) const {
  ds::dynamic_array<int> partWts(nP);
  for (int i = 0; i < number_of_partitions_; ++i) {
    int cut = cut_size(nP, i);
    assert(partition_cuts_[i] == cut);

    for (int j = 0; j < nP; ++j) {
      partWts[j] = 0;
    }

    int offset = partition_vector_offsets_[i];

    for (int j = 0; j < number_of_vertices_; ++j) {
      partWts[partition_vector_[offset + j]] += vertex_weights_[j];
    }

    check_part_weights_are_less_than(partWts, nP, maxWt);
  }
}
示例#4
0
/*
=======================================
    FMODEx 文件读取
=======================================
*/
CR_API sFMT_PRT*
load_fmodex (
  __CR_IO__ iDATIN*         datin,
  __CR_IN__ const sLOADER*  param
    )
{
    uint_t                  size;
    void_t*                 data;
    ansi_t*                 path;
    sFMT_PRT*               rett;
    FMOD_MODE               mode;
    iXMM_FMOD*              port;
    FMOD_SOUND*             sound;
    FMOD_RESULT             result;
    FMOD_CHANNEL*           channel;
    FMOD_CREATESOUNDEXINFO  ex_info;

    /* 必须先初始化 */
    if (s_fmodex == NULL)
        return (NULL);
    mode = FMOD_LOOP_OFF | FMOD_2D | FMOD_HARDWARE | FMOD_ACCURATETIME;

    /* 不支持文件区段功能 */
    switch (param->type)
    {
        case CR_LDR_ANSI:
            data = NULL;
            result = FMOD_System_CreateStream(s_fmodex, param->name.ansi,
                                              mode, NULL, &sound);
            break;

        case CR_LDR_WIDE:
            data = NULL;
            path = utf16_to_local(CR_LOCAL, param->name.wide);
            if (path == NULL)
                return (NULL);
            result = FMOD_System_CreateStream(s_fmodex, path, mode,
                                              NULL, &sound);
            mem_free(path);
            break;

        case CR_LDR_BUFF:
            if (cut_size(&size, param->buff.size))
                return (NULL);
            data = mem_dup(param->buff.data, param->buff.size);
            if (data == NULL)
                return (NULL);
            path = (ansi_t*)data;
            mode |= FMOD_OPENMEMORY;
            mem_zero(&ex_info, sizeof(ex_info));
            ex_info.cbsize = sizeof(ex_info);
            ex_info.length = size;
            result = FMOD_System_CreateStream(s_fmodex, path, mode,
                                              &ex_info, &sound);
            break;

        default:
            return (NULL);
    }

    /* 无法支持的格式 */
    if (result != FMOD_OK)
        goto _failure1;

    /* 生成播放通道对象 */
    result = FMOD_System_PlaySound(s_fmodex, FMOD_CHANNEL_FREE,
                                   sound, TRUE, &channel);
    if (result != FMOD_OK)
        goto _failure2;

    /* 生成媒体播放接口对象 */
    port = struct_new(iXMM_FMOD);
    if (port == NULL)
        goto _failure3;
    struct_zero(port, iXMM_FMOD);
    port->m_dat = data;
    port->m_snd = sound;
    port->m_chn = channel;
    if (!fmodex_info(port)) {
        iXMM_FMOD_release((iXMMEDIA*)port);
        return (NULL);
    }
    port->xmms.__volume__ = 100;
    port->xmms.__vptr__ = &s_xmms_vtbl;

    /* 返回读取的文件数据 */
    rett = struct_new(sFMT_PRT);
    if (rett == NULL) {
        iXMM_FMOD_release((iXMMEDIA*)port);
        return (NULL);
    }
    CR_NOUSE(datin);
    rett->type = CR_FMTZ_PRT;
    rett->port = (iPORT*)port;
    rett->more = "iXMMEDIA";
    rett->infor = port->m_inf;
    return (rett);

_failure3:
    FMOD_Channel_Stop(channel);
_failure2:
    FMOD_Sound_Release(sound);
_failure1:
    TRY_FREE(data);
    return (NULL);
}
示例#5
0
double conductance(const tGraph<T> &G,
                   const typename tGraph<T>::vertex_set &v)
{
    return (v.size() < 3 ? 0.0 :
            static_cast<double>(cut_size(G,v)) / G.subgraph_size(v) );
}