Skip to content

Instantly share code, notes, and snippets.

Avatar

Masahiro Sakai msakai

View GitHub Profile
@msakai
msakai / svm2lp.hs
Last active Aug 29, 2015
Convert libsvm format files to LP files
View svm2lp.hs
import Control.Monad
import qualified Data.Foldable as F
import Data.Default.Class
import Data.List.Split
import Data.Maybe
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
import Data.Map (Map)
import qualified Data.Map as Map
import qualified ToySolver.Data.MIP as MIP
@msakai
msakai / PatternSynonymExample.hs
Created Aug 16, 2015
An example usage of pattern synonyms
View PatternSynonymExample.hs
{-# LANGUAGE PatternSynonyms, ViewPatterns #-}
type Var = Int
type Monomial k = (k, [Var])
newtype Polynomial k = Polynomial [Monomial k]
pattern Var x = Polynomial [(1, [x])]
pattern Const k <- (asConst -> Just k) where
Const 0 = Polynomial []
@msakai
msakai / fakecoin.als
Created Jan 13, 2011
贋金パズルのAlloyモデル
View fakecoin.als
// 失敗版
sig Coin {}
abstract sig State {
  candidates : set Coin,
}
sig Branch extends State {
  left, right : set Coin, 
  eq, lt, gt : State
@msakai
msakai / FourierMotzkin.hs
Created Jan 18, 2011
Naïve implementation of Fourier-Motzkin Variable Elimination
View FourierMotzkin.hs
{-# OPTIONS_GHC -Wall #-}
-----------------------------------------------------------------------------
-- |
-- Module : FourierMotzkin
-- Copyright : (c) Masahiro Sakai 2011
-- License : BSD-style
--
-- Maintainer : masahiro.sakai@gmail.com
-- Stability : provisional
-- Portability : portable
@msakai
msakai / Simplex.hs
Created Jan 24, 2011
Naïve implementation of Simplex method
View Simplex.hs
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -Wall #-}
-----------------------------------------------------------------------------
-- |
-- Module : Simplex
-- Copyright : (c) Masahiro Sakai 2011
-- License : BSD-style
--
-- Maintainer : masahiro.sakai@gmail.com
-- Stability : provisional
@msakai
msakai / Cooper.hs
Created Jan 27, 2011
Naïve implementation of Cooper's algorithm
View Cooper.hs
{-# OPTIONS_GHC -Wall #-}
-----------------------------------------------------------------------------
-- |
-- Module : Cooper
-- Copyright : (c) Masahiro Sakai 2011
-- License : BSD-style
--
-- Maintainer : masahiro.sakai@gmail.com
-- Stability : provisional
-- Portability : portable
@msakai
msakai / LPFile.hs
Created Feb 24, 2011
A CPLEX lp format parser library
View LPFile.hs
{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind #-}
-----------------------------------------------------------------------------
-- |
-- Module : LPFile
-- Copyright : (c) Masahiro Sakai 2011
-- License : BSD-style
--
-- Maintainer : masahiro.sakai@gmail.com
-- Stability : provisional
-- Portability : portable
View Quiz2.hs
type S = ((Int,Int),(Int,Int),(Int,Int))
guess :: S -> S
guess ((a1,a2),(b1,b2),(c1,c2)) =
case (a1+b1) `compare` (b2+c1) of
EQ ->
if b1 < b2
then ((100,99),(99,100),(99,100))
else ((99,100),(100,99),(100,99))
LT ->
View SAT.rb
class SATSolver
def initialize
@cnt = 0
@ok = true
@clauses = []
@model = Hash.new
@watches = Hash.new
end
@msakai
msakai / TuplingExample.hs
Created Mar 25, 2011
タプル化の簡単な例
View TuplingExample.hs
module TuplingExample where
import Prelude hiding (even, odd)
even :: Int -> Bool
even n = if n==0 then True else odd (n-1)
odd :: Int -> Bool
odd n = if n==0 then False else even (n-1)