Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Module for implementing Simulated Annealing algorithm for single objective optimization.
author := "Daniel Barker"
"""
import random
# Pseudocode for Simulated Annealing Algorithm
while t_new > stopping temp:
for number of runs at each temp:
x_new, y_new = random neighboring value of x_old, y_old
calculate the cost c_new of this neighboring solution
if c_new – c_old >= 0:
This is a better solution, so move to it
else:
Calculate the probability of moving to the new worse solution
from __future__ import print_function
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
import pandas as pd
import numpy as np
import dash
from dash.dependencies import Input, Output, State, Event
import dash_core_components as dcc
import dash_html_components as html
@dcbark01
dcbark01 / heroku_test_app.py
Created April 30, 2018 18:19
heroku_test_app
import os
import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash(__name__)
server = app.server
@dcbark01
dcbark01 / google_sheet_tut.py
Last active December 29, 2021 20:05
Final code for accessing Google sheet data
from __future__ import print_function
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
import pandas as pd
SPREADSHEET_ID = # <Your spreadsheet ID>
RANGE_NAME = # <Your worksheet name>
# Import Supporting Libraries
import pandas as pd
# Import Dash Visualization Libraries
import dash_core_components as dcc
import dash_html_components as html
import dash_table_experiments as dt
import dash
from dash.dependencies import Input, Output, State
import plotly
@app.callback(Output('button-query', 'disabled'),
[Input('my-datatable', 'selected_row_indices')])
def show_hide_query_button(selected_row_indices):
""" Callback enables/disables the query button depending on the number of rows selected. """
if len(selected_row_indices) == 1:
return False
else:
return True
# Create our app layout
app = dash.Dash(__name__)
server = app.server
app.layout = html.Div([
html.H2('My Dash App'),
dt.DataTable(
id='my-datatable',
rows=df_ag.to_dict('records'),
editable=False,
row_selectable=True,
""" Sample App Code with Datatable """
# Import Supporting Libraries
import pandas as pd
# Import Dash Visualization Libraries
import dash_core_components as dcc
import dash_html_components as html
import dash_table_experiments as dt
import dash.dependencies
@app.callback(Output('datatable-subplots', 'figure'),
[Input('my-datatable', 'rows'),
Input('my-datatable', 'selected_row_indices')])
def update_figure(rows, selected_row_indices):
dff = pd.DataFrame(rows)
fig = plotly.tools.make_subplots(
rows=3, cols=1,
subplot_titles=('Beef', 'Pork', 'Poultry'),
shared_xaxes=True)
marker = {'color': ['#0074D9']*len(dff)}