code stringlengths 1 1.72M | language stringclasses 1
value |
|---|---|
# -*- coding: utf-8 -*-
from sys import *
class ca:
a = set()
am = set()
def __hash__(self):
return 0
def __repr__(self):
rep = "(ATRIBUTO/S: "
for elem in self.a:
rep += elem+' '
rep += ", CIERRE:"
for elem in self.am:
rep += ' '+elem
rep += ')'
return rep
def __str__(self):
rep = "(ATRIB... | Python |
# -*- coding: utf-8 -*-
from df import *
# Aca vamos a definir todos los atributos, y una funcion nos va a devolver un
# set, que vendria a ser el Esquema universal
# TODO
def getEsquemaUniversal():
return set(['Planilla.Numero', 'Planilla.Fecha', 'Encuestado.Edad', \
'Encuestado.Sexo', 'Encuestado.Ingreso_mensua... | Python |
# -*- coding: utf-8 -*-
from fprima import cierreAtributosAlfa
import copy
def calcular_FNBC (conjRi, Fpri, cierreAtr):
"""Descomposición en la forma normal de Boyce-Codd de un
conjunto de esquemas relacionales, para un F+ dado.
1º parámetro => conjunto de esquemas relacionales
2º parámetro => cierre de... | Python |
# -*- coding: utf-8 *-*
import sys
import unittest
from tests.dijkstra import *
from tests.prim import *
from tests.kruskal import *
if __name__ == '__main__':
unittest.main()
| Python |
# -*- coding: utf-8 *-*
import unittest
from tests_algorithms import *
from tests_graphs import *
from tests_structures import *
if __name__ == '__main__':
unittest.main()
| Python |
# -*- coding: utf-8 -*-
from graphs.listgraph import *
from graphs.matrixgraph import *
from graphs.generator import *
from timeit import Timer
class Main():
def __init__(self):
self.repeat = 5
def log(self, message):
print message
def measure(self):
start = 500
delta = ... | Python |
# -*- coding: utf-8 -*-
import unittest
from structures.unionfind import UnionFind
class UnionFindTest(unittest.TestCase):
def test_create_unionfind(self):
unionfind = UnionFind(['V1', 'V2'])
self.assertEqual(2, unionfind.count())
def test_create_unionfind_union_check_count(self):
u... | Python |
# -*- coding: utf-8 -*-
import unittest
from graphs.matrixgraph import MatrixGraph
class MatrixGraphTest(unittest.TestCase):
def setUp(self):
self.graph = MatrixGraph()
def test_add_two_vertices(self):
self.graph.add_vertex('V1')
self.graph.add_vertex('V2')
self.assertEqual(... | Python |
# -*- coding: utf-8 -*-
import unittest
from structures.hashtable import HashTable
class HashTableTest(unittest.TestCase):
def test_add_and_retrieve_item(self):
hash = HashTable()
key = "one"
hash.set(key, 1)
self.assertEqual(1, hash.get(key))
def test_add_and_retrieve_two_i... | Python |
# -*- coding: utf-8 -*-
import unittest
from structures.list import List
class ListTest(unittest.TestCase):
def test_create_list_check_empty(self):
list = List()
self.assertTrue(list.empty())
def test_create_list_add_element_check_emtpy(self):
list = List()
list.add(1)
... | Python |
# -*- coding: utf-8 -*-
import unittest
from graphs.listgraph import ListGraph
class ListGraphTest(unittest.TestCase):
def setUp(self):
self.graph = ListGraph()
def test_add_two_vertices(self):
self.graph.add_vertex('V1')
self.graph.add_vertex('V2')
self.assertEqual(2, self.... | Python |
# -*- coding: utf-8 *-*
import unittest
from graphs.listgraph import ListGraph
from graphs.matrixgraph import MatrixGraph
class DijkstraTest(unittest.TestCase):
def test_dijkstra_matrix(self):
self.run_test1(MatrixGraph())
self.run_test2(MatrixGraph())
self.run_test3(MatrixGraph())
d... | Python |
# -*- coding: utf-8 *-*
import unittest
from graphs.listgraph import ListGraph
from graphs.matrixgraph import MatrixGraph
class KruskalTest(unittest.TestCase):
def test_kruskal_matrix(self):
self.run_test1(MatrixGraph())
self.run_test2(MatrixGraph())
self.run_test3(MatrixGraph())
def... | Python |
# -*- coding: utf-8 *-*
import unittest
from graphs.listgraph import ListGraph
from graphs.matrixgraph import MatrixGraph
class PrimTest(unittest.TestCase):
def test_prim_matrix(self):
self.run_test1(MatrixGraph())
self.run_test2(MatrixGraph())
self.run_test3(MatrixGraph())
def test_... | Python |
# -*- coding: utf-8 -*-
import unittest
from structures.heap import Heap
class HeapTest(unittest.TestCase):
def test_add_n_elements_verify_order(self):
heap = Heap()
n = 65
#Insert elements in reverse order
for i in range(n):
heap.insert(n - i, n - i)
#Then ve... | Python |
# -*- coding: utf-8 -*-
from structures.hashtable import HashTable
from structures.list import List
from structures.heap import Heap
from structures.unionfind import UnionFind
from graphs.graph import *
class MatrixGraph(Graph):
def __init__(self):
self.__adjacency = []
self.__vertices = HashTabl... | Python |
# -*- coding: utf-8 -*-
from structures.list import List
from structures.heap import Heap
from structures.unionfind import UnionFind
from graphs.graph import *
class ListGraph(Graph):
def __init__(self, size=None):
self.__vertices = HashTable(size)
def add_vertex(self, name):
self.__vertices... | Python |
# -*- coding: utf-8 -*-
from graphs.matrixgraph import MatrixGraph
import random
import math
class Generator():
def __init__(self):
pass
def generate(self, vcount, factor, filename):
if factor > 1:
raise Exception('Invalid density factor.')
maxedges = (vcount - 1) * vcou... | Python |
# -*- coding: utf-8 -*-
from structures.hashtable import HashTable
class Graph():
NAME_SEPARATOR = '->'
ADJ_LIST_SEPARATOR = '||'
WEIGHT_SEPARATOR = ';'
def __init__(self):
pass
def load(self, filename):
pass
def save(self, filename):
raise Exception('save() not imp... | Python |
# -*- coding: utf-8 -*-
import sys
import unittest
from tests.matrixgraph import *
from tests.listgraph import *
if __name__ == '__main__':
unittest.main()
| Python |
# -*- coding: utf-8 -*-
import sys
import unittest
from tests.hashtable import *
from tests.heap import *
from tests.unionfind import *
from tests.list import *
if __name__ == '__main__':
unittest.main()
| Python |
# -*- coding: utf-8 -*-
from structures.hashtable import HashTable
class UnionFind():
def __init__(self, items):
self.sets = HashTable()
for item in items:
node = [item, None, 1]
self.sets[item] = node
self.__count = len(items)
def find(self, item):
no... | Python |
# -*- coding: utf-8 -*-
class HashTable():
__initial_size = 10000
def __init__(self, size=None):
self.__size = size
if size is None:
self.__size = HashTable.__initial_size
self.items = [None] * self.__size
self.__keys = []
def count(self):
return len... | Python |
# -*- coding: utf-8 -*-
class List():
def __init__(self):
self.__begin = None
self.__end = None
self.__current = None
self.__size = 0
def empty(self):
return self.__size == 0
def pop(self):
return self.pop_last()
def pop_last(self):
item = No... | Python |
# -*- coding: utf-8 -*-
class Heap():
__maxSize = 100
def __init__(self):
self.items = []
def insert(self, key, data):
item = [key, data]
self.items.append(item)
index = len(self.items) - 1
self.__heapify_up(index)
def change_key(self, index, key):
se... | Python |
# -*- coding: utf-8 *-*
class DBActors():
def __init__(self, filename):
self.filename = filename
self.file = None
self.currentline = None
def open(self):
if self.file is None:
self.file = open(self.filename)
# Read file until the start of actor/actres... | Python |
# -*- coding: utf-8 *-*
from structures.hashtable import HashTable
class Actor():
def __init__(self, name):
self.name = name
self.__titlesHash = HashTable()
self.titles = []
def add_title(self, title):
if self.__titlesHash[title] is None:
self.__titlesHash[title] ... | Python |
# -*- coding: utf-8 *-*
from structures.hashtable import HashTable
class Movie():
def __init__(self, title):
self.title = title
self.actors = HashTable()
def add_actor(self, actor):
if self.actors[actor] is None:
self.actors[actor] = True
| Python |
# -*- coding: utf-8 *-*
from graphs.listgraph import *
def add_edge(g, src, dest):
g.add_edge(src, dest, 1)
g.add_edge(dest, src, 1)
def generate_test1():
graph = ListGraph()
graph.add_vertex('A')
graph.add_vertex('B')
graph.add_vertex('C')
graph.add_vertex('D')
graph.add_vertex('E... | Python |
# -*- coding: utf-8 *-*
import sys
import unittest
from tests.dijkstra import *
if __name__ == '__main__':
unittest.main()
| Python |
# -*- coding: utf-8 *-*
import unittest
from tests_algorithms import *
from tests_graphs import *
from tests_structures import *
if __name__ == '__main__':
unittest.main()
| Python |
# -*- coding: utf-8 *-*
from graphs.matrixgraph import *
from graphs.listgraph import *
from structures.hashtable import HashTable
from imdb.dbactors import DBActors
# Total
# Around 1450000 actors
# Around 819000 actresses
# RAM: 524.8 MB
class Main():
def __init__(self):
pass
def main(self):
... | Python |
# -*- coding: utf-8 -*-
import unittest
from structures.unionfind import UnionFind
class UnionFindTest(unittest.TestCase):
def test_create_unionfind(self):
unionfind = UnionFind(['V1', 'V2'])
self.assertEqual(2, unionfind.count())
def test_create_unionfind_union_check_count(self):
u... | Python |
# -*- coding: utf-8 -*-
import unittest
from graphs.matrixgraph import MatrixGraph
class MatrixGraphTest(unittest.TestCase):
def setUp(self):
self.graph = MatrixGraph()
def test_add_two_vertices(self):
self.graph.add_vertex('V1')
self.graph.add_vertex('V2')
self.assertEqual(... | Python |
# -*- coding: utf-8 -*-
import unittest
from structures.hashtable import HashTable
class HashTableTest(unittest.TestCase):
def test_add_and_retrieve_item(self):
hash = HashTable()
key = "one"
hash.set(key, 1)
self.assertEqual(1, hash.get(key))
def test_add_and_retrieve_two_i... | Python |
# -*- coding: utf-8 -*-
import unittest
from structures.list import List
class ListTest(unittest.TestCase):
def test_create_list_check_empty(self):
list = List()
self.assertTrue(list.empty())
def test_create_list_add_element_check_emtpy(self):
list = List()
list.add(1)
... | Python |
# -*- coding: utf-8 -*-
import unittest
from graphs.listgraph import ListGraph
class ListGraphTest(unittest.TestCase):
def setUp(self):
self.graph = ListGraph()
def test_add_two_vertices(self):
self.graph.add_vertex('V1')
self.graph.add_vertex('V2')
self.assertEqual(2, self.... | Python |
# -*- coding: utf-8 *-*
import unittest
from graphs.listgraph import ListGraph
from graphs.matrixgraph import MatrixGraph
class DijkstraTest(unittest.TestCase):
def test_dijkstra_matrix(self):
self.run_test1(MatrixGraph())
self.run_test2(MatrixGraph())
self.run_test3(MatrixGraph())
... | Python |
# -*- coding: utf-8 -*-
import unittest
from structures.heap import Heap
class HeapTest(unittest.TestCase):
def test_add_n_elements_verify_order(self):
heap = Heap()
n = 65
#Insert elements in reverse order
for i in range(n):
heap.insert(n - i, n - i)
#Then ve... | Python |
# -*- coding: utf-8 -*-
from structures.hashtable import HashTable
from structures.list import List
from structures.heap import Heap
from structures.unionfind import UnionFind
from graphs.graph import *
class MatrixGraph(Graph):
def __init__(self):
self.__adjacency = []
self.__vertices = HashTabl... | Python |
# -*- coding: utf-8 -*-
from structures.list import List
from structures.heap import Heap
from structures.unionfind import UnionFind
from graphs.graph import *
class ListGraph(Graph):
def __init__(self, size=None):
self.__vertices = HashTable(size)
def add_vertex(self, name):
self.__vertices... | Python |
# -*- coding: utf-8 -*-
from graphs.matrixgraph import MatrixGraph
from graphs.graph import Edge
import random
import math
class Generator():
def __init__(self):
pass
def generate(self, vcount, factor, filename):
if factor > 1:
raise Exception('Invalid density factor.')
... | Python |
# -*- coding: utf-8 -*-
from structures.hashtable import HashTable
class Graph():
NAME_SEPARATOR = '->'
ADJ_LIST_SEPARATOR = '||'
WEIGHT_SEPARATOR = ';'
def __init__(self):
pass
def load(self, filename):
pass
def save(self, filename):
raise Exception('save() not imp... | Python |
# -*- coding: utf-8 -*-
import sys
import unittest
from tests.matrixgraph import *
from tests.listgraph import *
if __name__ == '__main__':
unittest.main()
| Python |
# -*- coding: utf-8 -*-
import sys
import unittest
from tests.hashtable import *
from tests.heap import *
from tests.unionfind import *
from tests.list import *
if __name__ == '__main__':
unittest.main()
| Python |
# -*- coding: utf-8 -*-
from structures.hashtable import HashTable
class UnionFind():
def __init__(self, items):
self.sets = HashTable()
for item in items:
node = UnionFindNode(item)
self.sets.set(item, node)
self.__count = len(items)
def find(self, item):
... | Python |
# -*- coding: utf-8 -*-
class HashTable():
__initial_size = 32
def __init__(self, size=None):
self.__size = size
if size is None:
self.__size = HashTable.__initial_size
self.items = [None] * self.__size
self.__keys = []
def count(self):
return len(se... | Python |
# -*- coding: utf-8 -*-
class List():
def __init__(self):
self.__begin = None
self.__end = None
self.__current = None
self.__size = 0
def empty(self):
return self.__size == 0
def pop(self):
return self.pop_last()
def pop_last(self):
item = No... | Python |
# -*- coding: utf-8 -*-
class Heap():
__maxSize = 100
def __init__(self):
self.items = []
def insert(self, key, data):
item = HeapItem(key, data)
self.items.append(item)
index = len(self.items) - 1
self.__heapify_up(index)
def change_key(self, index, key):
... | Python |
# -*- coding: utf-8 -*-
###############################################################################
# Import Modules
###############################################################################
import sys
import unittest
from backtracking import backtracking
from galeshapley import galeshapley
class TdaTP1(uni... | Python |
# -*- coding: utf-8 -*-
###############################################################################
# Import Modules
###############################################################################
import sys
from backtracking import backtracking
from galeshapley import galeshapley
def compareResult(filename, resu... | Python |
# -*- coding: utf-8 -*-
from collections import deque
from model.person import Person
from model.solution import Solution
class Backtracking:
def __init__(self, filename):
self.men = deque()
self.women = []
self.solution = None
self.__temp = Solution()
self.load_data(filen... | Python |
# -*- coding: utf-8 -*-
from collections import deque
from model.person import Person
from model.solution import Solution
class GaleShapley:
def __init__(self, filename):
self.singles = deque()
self.men = []
self.women = dict()
self.load_data(filename)
def load_data(self, fi... | Python |
# -*- coding: utf-8 -*-
from collections import deque
class Solution:
def __init__(self):
self.__pairs = deque()
def is_stable(self, pair):
for p in self.__pairs:
m1 = p[0]
w1 = p[1]
m2 = pair[0]
w2 = pair[1]
if ((m1.prefers(w2) an... | Python |
# -*- coding: utf-8 -*-
from collections import deque
class Person:
def __init__(self, name, preferences=[]):
"""Initializes the preferences hashtable.
O(n)"""
self.prefnames = deque()
self.name = name
self.fiancee = None
self.prefs = dict()
i = 0
f... | Python |
__author__="Sergey Karakovskiy, sergey at idsia fullstop ch"
__date__ ="$Feb 18, 2009 1:01:12 AM$"
class SimplePyAgent:
# class MarioAgent(Agent):
""" example of usage of AmiCo
"""
def getAction(self, obs):
ret = (0, 1, 0, 0, 0)
return ret
def giveReward(self, reward):
pass... | Python |
import numpy
__author__ = "Sergey Karakovskiy, sergey at idsia fullstop ch"
__date__ = "$May 1, 2009 2:46:34 AM$"
from marioagent import MarioAgent
class ForwardAgent(MarioAgent):
""" In fact the Python twin of the
corresponding Java ForwardAgent.
"""
action = None
actionStr = None
KEY_JUM... | Python |
__author__="Sergey Karakovskiy, sergey at idsia fullstop ch"
__date__ ="$May 2, 2009 7:54:12 PM$"
class MarioAgent:
# class MarioAgent(Agent):
""" An agent is an entity capable of producing actions, based on previous observations.
Generally it will also learn from experience. It can interact directly wi... | Python |
#!/usr/bin/python2.6
#
# Simple http server to emulate api.playfoursquare.com
import logging
import shutil
import sys
import urlparse
import SimpleHTTPServer
import BaseHTTPServer
class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
"""Handle playfoursquare.com requests, for testing."""
def do_GET(self... | Python |
#!/usr/bin/python
import datetime
import sys
import textwrap
import common
from xml.dom import pulldom
PARSER = """\
/**
* Copyright 2009 Joe LaPenna
*/
package com.joelapenna.foursquare.parsers;
import com.joelapenna.foursquare.Foursquare;
import com.joelapenna.foursquare.error.FoursquareError;
import com.joel... | Python |
#!/usr/bin/python
"""
Pull a oAuth protected page from foursquare.
Expects ~/.oget to contain (one on each line):
CONSUMER_KEY
CONSUMER_KEY_SECRET
USERNAME
PASSWORD
Don't forget to chmod 600 the file!
"""
import httplib
import os
import re
import sys
import urllib
import urllib2
import urlparse
import user
from xml.... | Python |
#!/usr/bin/python
import os
import subprocess
import sys
BASEDIR = '../main/src/com/joelapenna/foursquare'
TYPESDIR = '../captures/types/v1'
captures = sys.argv[1:]
if not captures:
captures = os.listdir(TYPESDIR)
for f in captures:
basename = f.split('.')[0]
javaname = ''.join([c.capitalize() for c in basena... | Python |
#!/usr/bin/python
import logging
from xml.dom import minidom
from xml.dom import pulldom
BOOLEAN = "boolean"
STRING = "String"
GROUP = "Group"
# Interfaces that all FoursquareTypes implement.
DEFAULT_INTERFACES = ['FoursquareType']
# Interfaces that specific FoursqureTypes implement.
INTERFACES = {
}
DEFAULT_CLA... | Python |
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "colombianCrush.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
| Python |
"""
Django settings for prueba project.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
imp... | Python |
'''
Created on 2/12/2013
@author: Juanpa y Yami
'''
from colombianCrush.core import *
class Figura(object):
"""Clase que representa a una figura que se puede ver en pantalla"""
def __init__(self, imagen):
self.id = imagen
self.imagen = Generador.cargarImagen(imagen)
def dibujar(s... | Python |
from elementos import Figura, Controlador | Python |
from django.conf.urls import patterns, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('colombianCrush.views',
# Examples:
# url(r'^$', 'prueba.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
# url(r'^admin/', include(admin.site.urls)),
url(r'^$'... | Python |
import os
from pyswip import Prolog
from random import randint
from django.conf import settings
#CONSTANTES DE IDENTIFICACION DE LOS ESTADOS DEL JUEGO
PASIVO = 0
#Estado en el que el jugador puede hacer su movimiento
ACTIVO = 1
#Estado en el que se reacomodan las fichas
DESTRUCCION = 2
#Estado en el que se consul... | Python |
from constantes import *
del(Prolog)
del(os)
del(randint)
del(settings) | Python |
"""
WSGI config for prueba project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
"""
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "colombianCrush.settings")
from django.... | Python |
'''
Created on 23/11/2013
@author: Juanpa y Yami
'''
from django.template import Context, RequestContext
from django.template.loader import get_template
from django.http import HttpResponse, HttpResponseRedirect
from colombianCrush.crush import Controlador, Figura
from django.views.decorators.csrf import csrf_protect
... | Python |
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "colombianCrush.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
| Python |
#!/usr/bin/env python
"""Branch and bound code for a 30 variable cardinality problem.
Written by Jacob Mattingley, March 2007, for EE364b Convex Optimization II,
Stanford University, Professor Stephen Boyd.
This file solves a (random) instance of the problem:
minimize card(x)
subject to Ax <= b
using bran... | Python |
#!/usr/bin/env python
"""Branch and bound code for a 30 variable cardinality problem.
Written by Jacob Mattingley, March 2007, for EE364b Convex Optimization II,
Stanford University, Professor Stephen Boyd.
This file solves a (random) instance of the problem:
minimize card(x)
subject to Ax <= b
using bran... | Python |
import sys
import numpy as np
import tree
import node
import cplex
#from cplex.exceptions import CplexError
def branchbound(c):
c.parameters.output.writelevel.set(0)
c.parameters.simplex.display.set(0)
rt = node.root(c)
tr = tree.tree(rt)
#tr.setup()
iter = 0
while True:
#-- ... | Python |
#This example shows how to formulate the wyndor glass co. problem
#The way that we model this problem can be altered to use modeling language
#But We still need to be clear about the model to be able to manipulate it
import cplex
from cplex.exceptions import CplexError
import sys
import numpy as np
c = cplex.Cplex()
... | Python |
#This example shows how to formulate the wyndor glass co. problem
#The way that we model this problem can be altered to use modeling language
#But We still need to be clear about the model to be able to manipulate it
import cplex
from cplex.exceptions import CplexError
import sys
import numpy as np
c = cplex.Cplex()
... | Python |
import cplex
import sys
def cpxsol(c):
c.parameters.mip.display.set(0)
c.parameters.preprocessing.presolve.set(0)
c.solve()
return c.solution.get_objective_value()
#cpxsol(c)
| Python |
import heapq
import cplex
import node
class tree:
def __init__(self, root):
self.global_up_bnd = 0
self.global_z = 0
# store the nodes in a priority queue
self.nodeq = []
heapq.heappush(self.nodeq, root)
def pop(self):
# pop the node with least priority... | Python |
import sys
import numpy as np
import heapq
from copy import copy, deepcopy
from math import ceil, floor
import cplex
class root:
def __init__(self, mip = None):
#need to organize the attributes
self.lp = mip
self.rootlp = cplex.Cplex( mip )
# convert the mip problem to lp... | Python |
import sys
import cplex
import numpy as np
from cplex.exceptions import CplexError
# c.variables.set_lower_bounds to fix values at 0 or 1
# c.solution.get_status() to know the status for logical control
# 1. optimal
# 2. unbounded
# 3. infeasible
# This function is going to be called over again
#--
def backtrack... | Python |
import sys
import cplex
import numpy as np
from cplex.exceptions import CplexError
# c.variables.set_lower_bounds to fix values at 0 or 1
# c.solution.get_status() to know the status for logical control
# 1. optimal
# 2. unbounded
# 3. infeasible
# This function is going to be called over again
def backtrack(c,... | Python |
import sys
import cplex
import numpy as np
from cplex.exceptions import CplexError
ca = cplex.Cplex()
ca.read(sys.argv[1])
#ca.read("bell5.mps")
#copy ca to c for self processing
c = cplex.Cplex(ca)
# change the type from MILP into LP (0:LP, 1:MILP)
c.set_problem_type(type=0)
# c.solve()
# d.solve()
# three vector... | Python |
import sys
import cplex
import numpy as np
from cplex.exceptions import CplexError
ca = cplex.Cplex()
ca.read(sys.argv[1])
#copy ca to c for self processing
c = cplex.Cplex(ca)
c.parameters.output.writelevel.set(0)
# record index of binary variables
int_var_idx = []
con_var_idx = []
for i in range(c.variables.get_... | Python |
import sys
import cplex
import numpy as np
from cplex.exceptions import CplexError
# c.variables.set_lower_bounds to fix values at 0 or 1
# c.solution.get_status() to know the status for logical control
# 1. optimal
# 2. unbounded
# 3. infeasible
# This function is going to be called over again
def backtrack_v(c,... | Python |
from numpy import *
import randgraph
#
n = 200
rho = 0.6
adj_mat = randgraph.randgraph(n, rho)
adj_mat_new = zeros([n,n])
for i in range(n-1):
adj_mat_new[i+1, 0:i+1] = adj_mat[0:i+1, i]
adj_mat_new[0:i+1, i+1] = adj_mat[0:i+1, i]
print adj_mat
print adj_mat_new
nodes = [[i] for i in range(n)]
S = []
S_b... | Python |
from numpy import *
from random import choice
import itertools
import sys
n = 50
rho = 0.4
def randgraph(n, rho):
int_lb = 1
int_ub = 10
adj_mat = zeros( (n-1, n-1) )
# Start from i to j+1
up_tri_ind = [(i,j) for j in range(n-1) for i in range(j+1)]
# Init the list of degrees at each node
... | Python |
#This module is for applying subgradient algorithm
#input: tolerance
#output: the list of primal solution, dual solution
#it internally calls the solvelr function with different lambda values
#to get primal and dual solutions
import sys
from lagrange import *
#print getidx(1,2,5)
iter = 0
N = 10
b = 40
t = 1
#report =... | Python |
from lagrange import *
bat_dual_rows = []
#for i in bat_dual_row_names:
#do subgradient for each case
iter = 0
N = 20
b = 100
#t = 1
#report = True
#rho = 0.8
eps = 1
def subgrad(prob, dual_rows):
A, b, sen, c = initlr(prob, dual_rows)
# set initial value of l
l = 0 * np.ones( len(dual_rows) )
z ... | Python |
import cplex
import random
import numpy as np
from cplex.exceptions import CplexError
#The ideal case is that
# createld(prob, rownames)
# solveld (prob, lambda, A, b)
def getidx(i,j,N):
return j*N + i + 1
def initip(seed=10, N=20, b=100):
random.seed(seed)
prob = cplex.Cplex()
prob.objective.se... | Python |
#read uflp problem as MIP
import sys
def get_words(line):
"""Return a list of the tokens in line."""
line = line.replace("\t", " ")
line = line.replace("\v", " ")
line = line.replace("\r", " ")
line = line.replace("\n", " ")
while line.count(" "):
line = line.replace(" ", " ")
lin... | Python |
import cplex
import readuflp
import sys
import os
def get_ind(i,j,N):
return j*N + i + 1
#stub
def gen_uflp(filename):
prob = cplex.Cplex()
num_fac, num_cty, fx_cost, cn_cost = readuflp.read_uflp(filename)
# add x_ij variables
for j in range(num_cty):
varnames = ["x" + str( get_ind(i,j, ... | Python |
#This is a file that generate a gap instances solved by cplex
import cplex
import random
import readgap
import os
def getidx(i,j,N):
return j*N + i + 1
def gengap(filename):
prob = cplex.Cplex()
nr, nj, c, a, b = readgap.readgap(filename)
print nr, nj, b
prob.objective.set_sense(prob.objective.se... | Python |
def get_words(line):
"""Return a list of the tokens in line."""
line = line.replace("\t", " ")
line = line.replace("\v", " ")
line = line.replace("\r", " ")
line = line.replace("\n", " ")
while line.count(" "):
line = line.replace(" ", " ")
line = line.strip()
return [word + " ... | Python |
#This is a file that generate a random instance of knapsack problem
import cplex
import random
# Thinking of design the covers and cover classes
# covers(A, b)
# covers.set_inequalities(prob)
# covers.update_inequalities(prob)
# construct the min_covers from A and b
# cover.ind
# cover.val
# cover.max_val
# cover.ism... | Python |
'''
Created on 11/07/2014
@author: Juanpa y Yami
'''
from cx_Freeze import setup, Executable
#includes = ["atexit", "PyQt4.QtGui", "numpy", "PIL", "pyfftw.builders"]
packages = ["GUI", "core"]
setup(
options={"build_exe":{"packages":packages, "excludes":["Tkinter"]}},
name="Transformada de Fourier",
... | Python |
'''
Created on 1/05/2014
@author: Juan Pablo Moreno - 20111020059
'''
import sys
from PyQt4.QtGui import QApplication
from GUI import VentanaMenu
def main():
app = QApplication(sys.argv)
ventana = VentanaMenu()
sys.exit(app.exec_())
if __name__ == '__main__':
main() | Python |
'''
Created on 3/06/2014
@author: Juan Pablo Moreno - 20111020059
@author:
@author:
@author:
'''
from __future__ import print_function
import os
from PIL import Image
import numpy as np
import pyfftw as pFT
_FORMATOS = ['PNG', 'JPEG', 'GIF', 'BMP']
def _abrirImagen(_ruta):
imagenes = []
if isinstance(_ru... | Python |
from implementacion import transformar, filtrar, invertir, NoCorrespondenError | Python |
Subsets and Splits
SQL Console for ajibawa-2023/Python-Code-Large
Provides a useful breakdown of language distribution in the training data, showing which languages have the most samples and helping identify potential imbalances across different language groups.