This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**************************************************************************** | |
FileName [ knapsack.h ] | |
Synopsis [ Knapsack Solver ] | |
Author [ Jui-Yang (Tony) Hsu] | |
Copyright [ Copyleft(c) 2017 NTUEE, Taiwan ] | |
****************************************************************************/ | |
#ifndef KNAPSACK_H | |
#define KNAPSACK_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**************************************************************************** | |
FileName [ knapsack.h ] | |
Synopsis [ Knapsack Solver ] | |
Author [ Jui-Yang (Tony) Hsu] | |
Copyright [ Copyleft(c) 2017 NTUEE, Taiwan ] | |
****************************************************************************/ | |
#ifndef KNAPSACK_H | |
#define KNAPSACK_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**************************************************************************** | |
FileName [ leq_solver.h ] | |
Synopsis [ Linear Equation Solver ] | |
Author [ Jui-Yang (Tony) Hsu] | |
Copyright [ Copyleft(c) 2017 NTUEE, Taiwan ] | |
****************************************************************************/ | |
#ifndef LEQ_SOLVER_H | |
#define LEQ_SOLVER_H | |
#include <vector> | |
#include <algorithm> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
//Use Disjoint Set Forest implementation | |
//father[i]: the idx of father of i-th node | |
//sz[i]:how many node view i-th node as ancestor(and father), including itself | |
//If father[i]=i, means the set i belongs to only has 1 element (which is i) | |
namespace djs{ | |
struct DisjointSet{ | |
int n; | |
std::vector<int> father; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::vector<int> bellman_ford(const Graph& g,int s){ | |
std::vector<int> dist(g.num_v,INT_MAX); | |
dist[s] = 0; | |
for(std::size_t i=0;i<g.num_v-1;++i){ | |
for(auto e:g.edges){ | |
if(dist[e.edge.first] != INT_MAX && dist[e.edge.first] + e.weight < dist[e.edge.second]) | |
dist[e.edge.second] = dist[e.edge.first] + e.weight; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::vector<int> dijkstra(const Graph& g,int s){ | |
std::vector<int> dist(g.num_v,INT_MAX); | |
std::vector<bool> b_set(g.num_v,false); | |
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > dist_pq; | |
dist[s] = 0; | |
dist_pq.push(make_pair(dist[s],s)); | |
while(!dist_pq.empty()){ | |
int cur_node = dist_pq.top().second; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Floyd Warshall algorithm | |
@Arg: graph data structure defined in graph.h | |
@Return: shortest distance table, dist[i][j] = min. cost from i to j | |
**/ | |
std::vector<std::vector<int> > floyd_warshall(const Graph& g){ | |
std::vector<std::vector<int> > dist(g.num_v,std::vector<int>(g.num_v,INT_MAX)); | |
// Init | |
for(std::size_t i=0;i<g.num_v;++i) | |
dist[i][i] = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
class Solution{ | |
public: | |
vector<int> findOrder(int numCourses, vector<pair<int, int>>& prerequisites) { | |
vector<int> seq; | |
// 0 -> not visited | |
// 1 -> visiting | |
// 2 -> already left |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DataContainer: | |
def __init__(self, data_dirs, batch_size, dev_batch_size, is_memmap, | |
is_bucket, num_workers=0, min_ilen=None, max_ilen=None, | |
half_batch_ilen=None, bucket_reverse=False, shuffle=True, | |
read_file=False, drop_last=False, pin_memory=True): | |
self.data_dirs = data_dirs | |
self.num_datasets = len(self.data_dirs) | |
self.batch_size = batch_size | |
self.is_memmap = is_memmap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import numpy as np | |
from pathlib import Path | |
from torch.utils.data import Dataset, DataLoader, Sampler | |
from torch.nn.utils.rnn import pad_sequence | |
import src.monitor.logger as logger | |
import random | |
# from numpy.lib.format import open_memmap |
OlderNewer